feat: plan management
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import { Document, Model, Schema, model } from "mongoose";
|
||||
import {
|
||||
CreatePlanPaymentParams,
|
||||
FindPlanPaymentsParams,
|
||||
IPlanPayment,
|
||||
IPlanPaymentsAdapter,
|
||||
} from "./PlanPayments.interface";
|
||||
|
||||
export interface IPlanPaymentDocument extends Omit<IPlanPayment, "id">, Document {}
|
||||
|
||||
export class PlanPaymentsAdapterMongoose implements IPlanPaymentsAdapter {
|
||||
schema: Schema;
|
||||
planPaymentList: Model<IPlanPaymentDocument>;
|
||||
|
||||
constructor() {
|
||||
this.schema = new Schema({
|
||||
userId: { type: Schema.Types.ObjectId, required: true, ref: "User" },
|
||||
subscriptionId: { type: Schema.Types.ObjectId, required: true, ref: "PlanSuscription" },
|
||||
amount: { type: Number, required: true, default: 0 },
|
||||
paymentDate: { type: Date, required: true, default: Date.now },
|
||||
paymentMethod: { type: String, required: false },
|
||||
status: { type: String, required: true },
|
||||
transactionId: { type: String, required: false },
|
||||
});
|
||||
|
||||
this.planPaymentList = model<IPlanPaymentDocument>("PlanPayment", this.schema);
|
||||
}
|
||||
|
||||
public async find(filters: FindPlanPaymentsParams): Promise<IPlanPayment[]> {
|
||||
return this.planPaymentList.find(filters).exec();
|
||||
}
|
||||
|
||||
public async create(data: CreatePlanPaymentParams): Promise<IPlanPayment> {
|
||||
return this.planPaymentList.create(data);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user