File size: 1,196 Bytes
430550f 5efe61a 430550f 5efe61a 430550f 5efe61a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | import mongoose, { Schema } from 'mongoose';
export enum TransactionType {
PAYMENT = 'payment',
DEPOSIT = 'deposit',
WITHDRAWL = 'withdrawl',
}
export const StatementSchema = new Schema({
amount: {
type: Number,
required: 'Transaction amount missing',
min: 0.01,
},
category: {
type: TransactionType,
lowercase: true,
required: 'Transaction type missing',
},
created_at: {
type: Date,
required: true,
default: Date.now()
},
user_id: {
type: Schema.Types.ObjectId,
ref: 'User',
required: true,
}
});
export const stringToTransactionType = (input: string) => {
switch (input) {
case 'payment':
return TransactionType.PAYMENT;
case 'deposit':
return TransactionType.DEPOSIT;
case 'withdrawl':
return TransactionType.WITHDRAWL;
default:
throw new Error('Invalid transaction type');
}
};
export interface TransactionInputDTO {
amount: number;
category: TransactionType;
user_id: string;
}
export const StatementModel = mongoose.model('statements', StatementSchema);
export type User = {
amout: number,
category: TransactionType,
balance: number,
created_at: Date,
}
|