|
@@ -7,11 +7,17 @@ module.exports = data => {
|
|
let indexStr = '';
|
|
let indexStr = '';
|
|
let has_ObjectId = false;
|
|
let has_ObjectId = false;
|
|
let has_Secret = false;
|
|
let has_Secret = false;
|
|
|
|
+ const configArr = [];
|
|
|
|
+ let configSearchStr = '';
|
|
for (let i = 0; i < columns.length; i++) {
|
|
for (let i = 0; i < columns.length; i++) {
|
|
const { title, type, required = false, remark, index } = columns[i];
|
|
const { title, type, required = false, remark, index } = columns[i];
|
|
const str = ` ${title}: { type: ${type || 'String'}, required: ${required} ${type === 'Secret' ? ', select: false' : ''} }, // ${remark || ''} \n`;
|
|
const str = ` ${title}: { type: ${type || 'String'}, required: ${required} ${type === 'Secret' ? ', select: false' : ''} }, // ${remark || ''} \n`;
|
|
columnStr += str;
|
|
columnStr += str;
|
|
- if (index) indexStr += `schema.index({ '${title}': 1 });\n`;
|
|
|
|
|
|
+ configArr.push(`'${required ? '!' : ''}${title}'`);
|
|
|
|
+ if (index) {
|
|
|
|
+ indexStr += `schema.index({ '${title}': 1 });\n`;
|
|
|
|
+ configSearchStr += `'${title}': '${title}' ,\n`;
|
|
|
|
+ }
|
|
if (!has_ObjectId && type === 'ObjectId') has_ObjectId = true;
|
|
if (!has_ObjectId && type === 'ObjectId') has_ObjectId = true;
|
|
else if (!has_Secret && type === 'Secret') has_Secret = true;
|
|
else if (!has_Secret && type === 'Secret') has_Secret = true;
|
|
}
|
|
}
|
|
@@ -34,5 +40,44 @@ module.exports = app => {
|
|
const { mongoose } = app;
|
|
const { mongoose } = app;
|
|
return mongoose.model('${modelName}', schema, ${name});
|
|
return mongoose.model('${modelName}', schema, ${name});
|
|
};
|
|
};
|
|
- `;
|
|
|
|
|
|
+
|
|
|
|
+module.exports = {
|
|
|
|
+ create: {
|
|
|
|
+ requestBody: [${configArr.join(',')}],
|
|
|
|
+ },
|
|
|
|
+ destroy: {
|
|
|
|
+ params: ["!id"],
|
|
|
|
+ service: "delete",
|
|
|
|
+ },
|
|
|
|
+ update: {
|
|
|
|
+ params: ["!id"],
|
|
|
|
+ requestBody: [${configArr.join(',')}],
|
|
|
|
+ },
|
|
|
|
+ show: {
|
|
|
|
+ parameters: {
|
|
|
|
+ params: ["!id"],
|
|
|
|
+ },
|
|
|
|
+ service: "fetch",
|
|
|
|
+ },
|
|
|
|
+ index: {
|
|
|
|
+ parameters: {
|
|
|
|
+ query: {
|
|
|
|
+ "meta.createdAt@start": "meta.createdAt@start",
|
|
|
|
+ "meta.createdAt@end": "meta.createdAt@end",
|
|
|
|
+ ${configSearchStr}
|
|
|
|
+ },
|
|
|
|
+ // options: {
|
|
|
|
+ // "meta.state": 0 // 默认条件
|
|
|
|
+ // },
|
|
|
|
+ },
|
|
|
|
+ service: "query",
|
|
|
|
+ options: {
|
|
|
|
+ query: ["skip", "limit"],
|
|
|
|
+ sort: ["meta.createdAt"],
|
|
|
|
+ desc: true,
|
|
|
|
+ count: true,
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+};
|
|
|
|
+`;
|
|
};
|
|
};
|