У меня есть 3 мес go схемы: счет-фактура, разрешение и запрос, все они имеют атрибут статуса, который я бы определил как Enum (каждый статус - это diff для каждой модели), я подумал определить глобальную схему под названием status или определить 3 SchemasStatus для каждого, я не нашел способа, как определить атрибуты динамического c перечисления для каждой схемы счета, разрешения и запроса!
export {};
const mongoose = require('mongoose');
/**
* Invoice Schema
* @private
*/
const invoiceSchema = new mongoose.Schema(
{
request: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Request',
required: true
},
number: {
type: Number,
required: true
},
price:{
type: Number,
required: true
},
dueDate:{
type: Date,
required: true
},
download:{
type: Number
},
status:{
type: [string],
},
},
{
timestamps: true
}
);
const ALLOWED_FIELDS = ['id', 'request', 'number', 'price', 'dueDate'];
/**
* @typedef Invoice
*/
const Invoice = mongoose.model('Invoice', invoiceSchema);
Invoice.ALLOWED_FIELDS = ALLOWED_FIELDS;
module.exports = Invoice;
export {};
const mongoose = require('mongoose');
/**
* Permit Schema
* @private
*/
const permitSchema = new mongoose.Schema(
{
request: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Request',
required: true
},
ownerCitizen: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Citizen',
required: true
},
ownerOrganisation: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Organisation',
required: true
},
expireDate:{
type: Date,
required: true
},
download:{
type: Number
},
status:{
type: [string],
},
},
{
timestamps: true
}
);
const ALLOWED_FIELDS = ['id', 'request', 'owner', 'expireDate','download'];
/**
* @typedef Employee
*/
const Permit = mongoose.model('Permit', permitSchema);
Permit.ALLOWED_FIELDS = ALLOWED_FIELDS;
module.exports = Permit;