2020-11-11 15:23:39 +08:00
|
|
|
import path from 'path';
|
2020-12-18 09:04:40 +08:00
|
|
|
|
|
|
|
import Database, { registerFields } from '@nocobase/database';
|
2020-11-11 15:23:39 +08:00
|
|
|
import Resourcer from '@nocobase/resourcer';
|
2020-12-18 09:04:40 +08:00
|
|
|
|
|
|
|
import * as fields from './fields';
|
2020-12-18 15:50:03 +08:00
|
|
|
// import hooks from './hooks';
|
2020-11-29 16:26:53 +08:00
|
|
|
import login from './actions/login';
|
|
|
|
import register from './actions/register';
|
|
|
|
import logout from './actions/logout';
|
|
|
|
import check from './actions/check';
|
2020-12-18 15:50:03 +08:00
|
|
|
import { makeOptions } from './hooks/collection-after-create';
|
2020-12-18 09:04:40 +08:00
|
|
|
|
2020-11-11 15:23:39 +08:00
|
|
|
export default async function (options = {}) {
|
|
|
|
const database: Database = this.database;
|
|
|
|
const resourcer: Resourcer = this.resourcer;
|
|
|
|
|
2020-12-18 09:04:40 +08:00
|
|
|
registerFields(fields);
|
|
|
|
|
2020-11-11 20:57:18 +08:00
|
|
|
database.import({
|
2020-11-11 15:23:39 +08:00
|
|
|
directory: path.resolve(__dirname, 'collections'),
|
|
|
|
});
|
2020-11-29 16:26:53 +08:00
|
|
|
|
2020-12-18 15:50:03 +08:00
|
|
|
database.addHook('afterTableInit', (table) => {
|
|
|
|
const { createdBy, updatedBy } = table.getOptions();
|
|
|
|
const fieldsToMake = { createdBy, updatedBy };
|
|
|
|
Object.keys(fieldsToMake)
|
|
|
|
.filter(type => Boolean(fieldsToMake[type]))
|
|
|
|
.map(type => table.addField(makeOptions(type, fieldsToMake[type])));
|
|
|
|
});
|
|
|
|
|
|
|
|
// hooks.call(this);
|
2020-12-18 09:04:40 +08:00
|
|
|
|
2020-12-02 13:48:19 +08:00
|
|
|
resourcer.registerActionHandlers({
|
2020-11-29 16:26:53 +08:00
|
|
|
'users:login': login,
|
|
|
|
'users:register': register,
|
|
|
|
'users:logout': logout,
|
|
|
|
'users:check': check,
|
|
|
|
});
|
|
|
|
|
|
|
|
resourcer.import({
|
|
|
|
directory: path.resolve(__dirname, 'resources'),
|
|
|
|
});
|
2020-11-11 15:23:39 +08:00
|
|
|
}
|