64 lines
1.1 KiB
TypeScript
64 lines
1.1 KiB
TypeScript
import { Schema, model, models, Model } from 'mongoose';
|
|
import { AppSchema as AppType } from '@/types/mongoSchema';
|
|
|
|
const AppSchema = new Schema({
|
|
userId: {
|
|
type: Schema.Types.ObjectId,
|
|
ref: 'user',
|
|
required: true
|
|
},
|
|
name: {
|
|
type: String,
|
|
required: true
|
|
},
|
|
avatar: {
|
|
type: String,
|
|
default: '/icon/logo.png'
|
|
},
|
|
intro: {
|
|
type: String,
|
|
default: ''
|
|
},
|
|
updateTime: {
|
|
type: Date,
|
|
default: () => new Date()
|
|
},
|
|
share: {
|
|
topNum: {
|
|
type: Number,
|
|
default: 0
|
|
},
|
|
isShare: {
|
|
type: Boolean,
|
|
default: false
|
|
},
|
|
isShareDetail: {
|
|
// share model detail info. false: just show name and intro
|
|
type: Boolean,
|
|
default: false
|
|
},
|
|
intro: {
|
|
type: String,
|
|
default: '',
|
|
maxlength: 150
|
|
},
|
|
collection: {
|
|
type: Number,
|
|
default: 0
|
|
}
|
|
},
|
|
modules: {
|
|
type: Array,
|
|
default: []
|
|
}
|
|
});
|
|
|
|
try {
|
|
AppSchema.index({ updateTime: -1 });
|
|
AppSchema.index({ 'share.collection': -1 });
|
|
} catch (error) {
|
|
console.log(error);
|
|
}
|
|
|
|
export const App: Model<AppType> = models['app'] || model('app', AppSchema);
|