import { Documents, Prisma } from "@prisma/client"; import { Document } from "le-coffre-resources/dist/SuperAdmin"; import DocumentsRepository from "@Repositories/DocumentsRepository"; import BaseService from "@Services/BaseService"; import { Service } from "typedi"; @Service() export default class DocumentsService extends BaseService { constructor(private documentsRepository: DocumentsRepository) { super(); } /** * @description : Get all documents * @throws {Error} If documents cannot be get */ public async get(query: any) { return this.documentsRepository.findMany(query); } /** * @description : Create a new document * @throws {Error} If document cannot be created */ public async create(document: Document): Promise { return this.documentsRepository.create(document); } /** * @description : Create new documents * @throws {Error} If documents or one of them cannot be created */ public async createMany(documents: Document[]): Promise { return this.documentsRepository.createMany(documents); } /** * @description : Modify a document * @throws {Error} If document cannot be modified */ public async update(uid: string, document: Document): Promise { return this.documentsRepository.update(uid, document); } /** * @description : Delete a document * @throws {Error} If document cannot be deleted */ public async delete(uid: string): Promise { return this.documentsRepository.delete(uid); } /** * @description : Get a document by uid * @throws {Error} If document cannot be get by uid */ public async getByUid(uid: string, query?: any) { return this.documentsRepository.findOneByUid(uid, query); } }