forked from Yara724/api
Initial commit after migration to gitea
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectModel } from '@nestjs/mongoose';
|
||||
import { FilterQuery, Model, UpdateQuery } from 'mongoose';
|
||||
import { BlameDocumentModel } from '../schema/blame-document.schema';
|
||||
|
||||
@Injectable()
|
||||
export class BlameDocumentDbService {
|
||||
constructor(
|
||||
@InjectModel(BlameDocumentModel.name)
|
||||
private readonly blameDocumentModel: Model<BlameDocumentModel>,
|
||||
) {}
|
||||
|
||||
async create(createDto: Partial<BlameDocumentModel>): Promise<BlameDocumentModel> {
|
||||
const newDocument = new this.blameDocumentModel(createDto);
|
||||
return newDocument.save();
|
||||
}
|
||||
|
||||
async findOne(filter: FilterQuery<BlameDocumentModel>): Promise<BlameDocumentModel | null> {
|
||||
return this.blameDocumentModel.findOne(filter).lean();
|
||||
}
|
||||
|
||||
async findAll(filter: FilterQuery<BlameDocumentModel>): Promise<BlameDocumentModel[]> {
|
||||
return this.blameDocumentModel.find(filter).lean();
|
||||
}
|
||||
|
||||
async findById(id: string): Promise<BlameDocumentModel | null> {
|
||||
return this.blameDocumentModel.findById(id).lean();
|
||||
}
|
||||
|
||||
async findByIdAndUpdate(
|
||||
id: string,
|
||||
updateDto: UpdateQuery<BlameDocumentModel>,
|
||||
): Promise<BlameDocumentModel | null> {
|
||||
return this.blameDocumentModel.findByIdAndUpdate(id, updateDto, { new: true }).lean();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import { InjectModel } from "@nestjs/mongoose";
|
||||
import { Model, Types } from "mongoose";
|
||||
import { BlameVideosModel } from "src/request-management/entities/schema/blame-video.schema";
|
||||
|
||||
export class BlameVideoDbService {
|
||||
constructor(
|
||||
@InjectModel(BlameVideosModel.name)
|
||||
private readonly blameVideoModel: Model<BlameVideosModel>,
|
||||
) {}
|
||||
|
||||
async create(video: BlameVideosModel): Promise<BlameVideosModel> {
|
||||
return await this.blameVideoModel.create(video);
|
||||
}
|
||||
|
||||
async findOne(id: string): Promise<BlameVideosModel> {
|
||||
return await this.blameVideoModel.findOne(new Types.ObjectId(id));
|
||||
}
|
||||
|
||||
async findOneByRequestId(id: string): Promise<BlameVideosModel> {
|
||||
return await this.blameVideoModel.findById(id);
|
||||
}
|
||||
|
||||
async findById(id: string): Promise<BlameVideosModel | null> {
|
||||
return this.blameVideoModel.findById(id).lean();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import { InjectModel } from "@nestjs/mongoose";
|
||||
import { Model, Types } from "mongoose";
|
||||
import { BlameVoicesModel } from "../schema/blame-voice.schema";
|
||||
|
||||
export class BlameVoiceDbService {
|
||||
constructor(
|
||||
@InjectModel(BlameVoicesModel.name)
|
||||
private readonly blameVoiceModel: Model<BlameVoicesModel>,
|
||||
) {}
|
||||
|
||||
async create(Voice: BlameVoicesModel): Promise<BlameVoicesModel> {
|
||||
return await this.blameVoiceModel.create(Voice);
|
||||
}
|
||||
|
||||
async findOne(id: string): Promise<BlameVoicesModel> {
|
||||
return await this.blameVoiceModel.findOne(new Types.ObjectId(id));
|
||||
}
|
||||
|
||||
async findById(id: string): Promise<BlameVoicesModel | null> {
|
||||
return this.blameVoiceModel.findById(id).lean();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
import { InjectModel } from "@nestjs/mongoose";
|
||||
import { FilterQuery, Model, Types, UpdateQuery } from "mongoose";
|
||||
import { RequestManagementModel } from "../schema/request-management.schema";
|
||||
|
||||
export class RequestManagementDbService {
|
||||
constructor(
|
||||
@InjectModel(RequestManagementModel.name)
|
||||
private readonly requestModel: Model<RequestManagementModel>,
|
||||
) {}
|
||||
|
||||
async create(
|
||||
request: RequestManagementModel,
|
||||
): Promise<RequestManagementModel> {
|
||||
return await this.requestModel.create(request);
|
||||
}
|
||||
|
||||
async findOne(id: string) {
|
||||
return await this.requestModel.findOne(new Types.ObjectId(id));
|
||||
}
|
||||
|
||||
async findAll(filter?: FilterQuery<RequestManagementModel>) {
|
||||
return await this.requestModel.find({ ...filter });
|
||||
}
|
||||
|
||||
async findAllAndPagination(query, currentPage, resPerPage?) {
|
||||
const responsePerPage = resPerPage | 1;
|
||||
const skipPge = responsePerPage * (Number(currentPage) - 1);
|
||||
return await this.requestModel
|
||||
.find(query)
|
||||
.limit(responsePerPage)
|
||||
.skip(skipPge);
|
||||
}
|
||||
|
||||
async countByFilter(
|
||||
filter: FilterQuery<RequestManagementModel>,
|
||||
): Promise<number> {
|
||||
return await this.requestModel.countDocuments(filter);
|
||||
}
|
||||
|
||||
async findAndUpdate(
|
||||
filter: FilterQuery<RequestManagementModel>,
|
||||
update: UpdateQuery<RequestManagementModel>,
|
||||
) {
|
||||
return await this.requestModel.findByIdAndUpdate(filter, update);
|
||||
}
|
||||
|
||||
async findOneAndUpdate(
|
||||
filter: FilterQuery<RequestManagementModel>,
|
||||
update: UpdateQuery<RequestManagementModel>,
|
||||
options: {
|
||||
new?: boolean;
|
||||
upsert?: boolean;
|
||||
runValidators?: boolean;
|
||||
} = {},
|
||||
): Promise<RequestManagementModel | null> {
|
||||
try {
|
||||
const updatedDoc = await this.requestModel.findOneAndUpdate(
|
||||
filter,
|
||||
update,
|
||||
{
|
||||
new: options.new ?? true, // Return updated doc by default
|
||||
upsert: options.upsert ?? false, // Don’t create new if not found
|
||||
runValidators: options.runValidators ?? true,
|
||||
},
|
||||
);
|
||||
|
||||
return updatedDoc;
|
||||
} catch (error) {
|
||||
console.error(
|
||||
`❌ [RequestManagementDbService] findOneAndUpdate failed`,
|
||||
error,
|
||||
);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async findByIdAndUpdate(
|
||||
id: string,
|
||||
update: UpdateQuery<RequestManagementModel>,
|
||||
) {
|
||||
return await this.requestModel.findByIdAndUpdate(
|
||||
{ _id: new Types.ObjectId(id) },
|
||||
update,
|
||||
);
|
||||
}
|
||||
|
||||
async aggregate(filter?) {
|
||||
return await this.requestModel.aggregate(filter);
|
||||
}
|
||||
|
||||
async updateMany(filter?, update?) {
|
||||
return await this.requestModel.updateMany(filter, update);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import { InjectModel } from "@nestjs/mongoose";
|
||||
import { Model, Types } from "mongoose";
|
||||
import { UserSignModel } from "../schema/sign.schema";
|
||||
|
||||
export class UserSignDbService {
|
||||
constructor(
|
||||
@InjectModel(UserSignModel.name)
|
||||
private readonly blameVoiceModel: Model<UserSignModel>,
|
||||
) {}
|
||||
|
||||
async create(sign: UserSignModel): Promise<UserSignModel> {
|
||||
return await this.blameVoiceModel.create(sign);
|
||||
}
|
||||
|
||||
async findOne(id: string): Promise<UserSignModel> {
|
||||
return await this.blameVoiceModel.findOne(new Types.ObjectId(id));
|
||||
}
|
||||
|
||||
async findById(id: string): Promise<UserSignModel | null> {
|
||||
// Use your correct Model type
|
||||
return this.blameVoiceModel.findById(id).lean();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user