mirror of
https://github.com/labring/FastGPT.git
synced 2025-08-01 20:27:45 +00:00
48 lines
998 B
TypeScript
48 lines
998 B
TypeScript
import { connectionMongo, type Model } from '@fastgpt/service/common/mongo';
|
|
const { Schema, model, models } = connectionMongo;
|
|
import { BillSchema as BillType } from '@/types/common/bill';
|
|
import { BillSourceMap } from '@/constants/user';
|
|
|
|
const BillSchema = new Schema({
|
|
userId: {
|
|
type: Schema.Types.ObjectId,
|
|
ref: 'user',
|
|
required: true
|
|
},
|
|
appName: {
|
|
type: String,
|
|
default: ''
|
|
},
|
|
appId: {
|
|
type: Schema.Types.ObjectId,
|
|
ref: 'model',
|
|
required: false
|
|
},
|
|
time: {
|
|
type: Date,
|
|
default: () => new Date()
|
|
},
|
|
total: {
|
|
type: Number,
|
|
required: true
|
|
},
|
|
source: {
|
|
type: String,
|
|
enum: Object.keys(BillSourceMap),
|
|
required: true
|
|
},
|
|
list: {
|
|
type: Array,
|
|
default: []
|
|
}
|
|
});
|
|
|
|
try {
|
|
BillSchema.index({ userId: 1 });
|
|
BillSchema.index({ time: 1 }, { expireAfterSeconds: 90 * 24 * 60 * 60 });
|
|
} catch (error) {
|
|
console.log(error);
|
|
}
|
|
|
|
export const Bill: Model<BillType> = models['bill'] || model('bill', BillSchema);
|