mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-07-01 18:52:20 +08:00
* feat: getRepository * getRepository return type * export action * add: acl * feat: setResourceAction * feat: action alias * chore: code struct * feat: removeResourceAction * chore: file name * ignorecase * remove ACL * feat: ACL * feat: role toJSON * using emit * chore: test * feat: plugin-acl * feat: acl with predicate * grant universal action test * grant action test * update resource action test * revoke resource action * usingActionsConfig switch * plugin-ui-schema-storage * remove global acl instance * fix: collection manager with sqlite * add own action listener * add acl middleware * add acl allowConfigure strategy option * add plugin-acl allowConfigure * change acl resourceName * add acl middleware merge params * bugfix * append fields on acl action params * acl middleware parse template * fix: collection-manager migrate Co-authored-by: chenos <chenlinxh@gmail.com>
33 lines
937 B
TypeScript
33 lines
937 B
TypeScript
import { SyncOptions } from 'sequelize';
|
|
import Database, { MagicAttributeModel } from '@nocobase/database';
|
|
|
|
interface LoadOptions {
|
|
// TODO
|
|
skipExist?: boolean;
|
|
}
|
|
|
|
export class FieldModel extends MagicAttributeModel {
|
|
get db(): Database {
|
|
return (<any>this.constructor).database;
|
|
}
|
|
|
|
async load(loadOptions?: LoadOptions) {
|
|
const { skipExist = false } = loadOptions || {};
|
|
const collectionName = this.get('collectionName');
|
|
if (!this.db.hasCollection(collectionName)) {
|
|
throw new Error(`${collectionName} collection does not exist.`);
|
|
}
|
|
const collection = this.db.getCollection(collectionName);
|
|
const name = this.get('name');
|
|
if (skipExist && collection.hasField(name)) {
|
|
return collection.getField(name);
|
|
}
|
|
return collection.setField(name, this.get());
|
|
}
|
|
|
|
async migrate(options?: SyncOptions) {
|
|
const field = await this.load();
|
|
await field.sync(options);
|
|
}
|
|
}
|