Archived
2
This repository has been archived on 2023-03-02. You can view files and clone it, but cannot push or open issues or pull requests.
definma-api/src/models/model.ts

20 lines
527 B
TypeScript
Raw Normal View History

2020-08-13 12:07:40 +02:00
import mongoose from 'mongoose';
2020-08-19 13:48:47 +02:00
import db from '../db';
2020-08-13 12:07:40 +02:00
const ModelSchema = new mongoose.Schema({
2020-08-19 13:48:47 +02:00
group: {type: String, index: {unique: true}},
models: [new mongoose.Schema({
2020-08-20 10:42:55 +02:00
name: String,
2020-08-19 13:48:47 +02:00
url: String,
label: String
} ,{ _id : false })]
2020-08-13 12:07:40 +02:00
});
2020-08-19 13:48:47 +02:00
// changelog query helper
ModelSchema.query.log = function <Q extends mongoose.DocumentQuery<any, any>> (req) {
db.log(req, this);
return this;
}
ModelSchema.index({group: 1});
2020-08-13 12:07:40 +02:00
export default mongoose.model<any, mongoose.Model<any, any>>('model', ModelSchema);