import { FindClientAccountsParams, IClientAccountsAdapter, IClientAccount, CreateClientAccountParams, } from "./ClientAccounts.Interface"; import { Document, Model, Schema, model } from "mongoose"; export interface IClientAccountDocument extends Omit, Document {} export class ClientAccountsAdapterMongoose implements IClientAccountsAdapter { schema: Schema; clientAccountList: Model; constructor() { this.schema = new Schema({ clientId: { type: Schema.Types.ObjectId, required: true, ref: "Client", }, amount: { type: Number, required: true, default: 0 }, creationDate: { type: Date, required: true, default: Date.now }, }); this.clientAccountList = model( "ClientAccount", this.schema ); } public async create( data: CreateClientAccountParams ): Promise { return await this.clientAccountList.create(data); } public async delete(id: string): Promise { await this.clientAccountList.deleteOne({ _id: id }); } public async find( filters: FindClientAccountsParams ): Promise { return this.clientAccountList.find(filters).exec(); } public async findOne( filters: Omit ): Promise { return this.clientAccountList.findOne(filters).exec(); } }