You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use the schema to create the expenditure service. Change interface name to ExpenditureProps. Any interface with I change it to interfaceNameProps. When storing or updating the data, make sure you save the expenditure with it's mode of payment. Validate the mode of payment and the fields corresponding to it
The text was updated successfully, but these errors were encountered:
import mongoose, { Schema, Document, Model } from 'mongoose';
interface IExpense extends Document {
item: string;
itemId: string;
quantity: number;
amountPerQuantity: number;
totalAmount: number;
description: string;
modeOfPayment: 'cash' | 'mobileMoney' | 'bank';
expenseHead?: number;
subExpense?: number;
receiptNumber: string;
academicYear: number;
term: string;
recordedBy: string;
time: string;
date: string;
warehouseId: string;
accountId: string;
}
interface IMobileMoneyPayment extends IExpense {
referenceNumber: string;
paymentNumber: string;
networkType: string;
}
interface IBankPayment extends IExpense {
referenceNumber: string;
bankAccount: string;
bankName: string;
bankBranch: string;
}
const baseOptions = {
discriminatorKey: 'modeOfPayment',
collection: 'expenses',
};
const ExpenseSchema: Schema = new Schema(
{
item: { type: String, required: true },
itemId: { type: String, required: true },
quantity: { type: Number, required: true },
amountPerQuantity: { type: Number, required: true },
totalAmount: { type: Number, required: true },
description: { type: String, required: true },
modeOfPayment: { type: String, required: true, enum: ['cash', 'mobileMoney', 'bank'] },
expenseHead: { type: Number, required: false },
subExpense: { type: Number, required: false },
receiptNumber: { type: String, required: true },
academicYear: { type: Number, required: true },
term: { type: String, required: true },
recordedBy: { type: String, required: true },
time: { type: String, required: true },
date: { type: String, required: true },
warehouseId: { type: String, required: true },
accountId: { type: String, required: true },
},
baseOptions
);
const Expense: Model = mongoose.model('Expense', ExpenseSchema);
const MobileMoneyPaymentSchema: Schema = new Schema({
referenceNumber: { type: String, required: true },
paymentNumber: { type: String, required: true },
networkType: { type: String, required: true },
});
const BankPaymentSchema: Schema = new Schema({
referenceNumber: { type: String, required: true },
bankAccount: { type: String, required: true },
bankName: { type: String, required: true },
bankBranch: { type: String, required: true },
});
const MobileMoneyPayment: Model = Expense.discriminator(
'mobileMoney',
MobileMoneyPaymentSchema
);
const BankPayment: Model = Expense.discriminator(
'bank',
BankPaymentSchema
);
export { Expense, MobileMoneyPayment, BankPayment, IExpense, IMobileMoneyPayment, IBankPayment };
use the schema to create the expenditure service. Change interface name to ExpenditureProps. Any interface with I change it to interfaceNameProps. When storing or updating the data, make sure you save the expenditure with it's mode of payment. Validate the mode of payment and the fields corresponding to it
The text was updated successfully, but these errors were encountered: