This commit is contained in:
chenos 2021-07-23 21:28:57 +08:00
parent 6b419fc5cd
commit 91ecd98071
3 changed files with 16 additions and 0 deletions

View File

@ -17,6 +17,8 @@ import { middlewares } from '@nocobase/server';
useStaticServer: !(process.env.APP_USE_STATIC_SERVER === 'false' || !process.env.APP_USE_STATIC_SERVER), useStaticServer: !(process.env.APP_USE_STATIC_SERVER === 'false' || !process.env.APP_USE_STATIC_SERVER),
})); }));
await api.database.getModel('collections').load({ skipExisting: true });
api.listen(process.env.API_PORT, () => { api.listen(process.env.API_PORT, () => {
console.log(`http://localhost:${process.env.API_PORT}/`); console.log(`http://localhost:${process.env.API_PORT}/`);
}); });

View File

@ -0,0 +1,12 @@
import { Model, ModelCtor } from '@nocobase/database';
import { actions, middlewares } from '@nocobase/actions';
import { sort } from '@nocobase/actions/src/actions/common';
import { cloneDeep, omit } from 'lodash';
export const create = async (ctx: actions.Context, next: actions.Next) => {
await actions.common.create(ctx, async () => {});
const { associated } = ctx.action.params;
await associated.migrate();
console.log('associated.migrate');
await next();
}

View File

@ -3,6 +3,7 @@ import { Application } from '@nocobase/server';
import { registerModels, Table } from '@nocobase/database'; import { registerModels, Table } from '@nocobase/database';
import * as models from './models'; import * as models from './models';
import { createOrUpdate, findAll } from './actions'; import { createOrUpdate, findAll } from './actions';
import { create } from './actions/fields';
export default async function (this: Application, options = {}) { export default async function (this: Application, options = {}) {
const database = this.database; const database = this.database;
@ -15,6 +16,7 @@ export default async function (this: Application, options = {}) {
model.set('name', model.get('key')); model.set('name', model.get('key'));
} }
}); });
this.resourcer.registerActionHandler('collections.fields:create', create);
this.resourcer.registerActionHandler('collections:findAll', findAll); this.resourcer.registerActionHandler('collections:findAll', findAll);
this.resourcer.registerActionHandler('collections:createOrUpdate', createOrUpdate); this.resourcer.registerActionHandler('collections:createOrUpdate', createOrUpdate);
} }