Download api/src/model/statement.ts from Jessedbrown/warran: direct link, hf CLI and curl.
- Browser
- Download file 1.2 kB
-
https://huggingface.co/Jessedbrown/warran/resolve/main/api/src/model/statement.ts
- Command line
-
hf download hf://Jessedbrown/warran/api/src/model/statement.ts
-
curl -L -o statement.ts https://huggingface.co/Jessedbrown/warran/resolve/main/api/src/model/statement.ts
1.2 kB
| 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, | |
| } | |