fix: firstOrCreate

This commit is contained in:
chenos 2025-03-10 22:07:33 +08:00
parent 8741c26a86
commit 43767a9212
2 changed files with 18 additions and 4 deletions

View File

@ -11,12 +11,12 @@ import { Model, Transaction } from '@nocobase/database';
import PluginLocalizationServer from '@nocobase/plugin-localization';
import { Plugin } from '@nocobase/server';
import { tval } from '@nocobase/utils';
import _ from 'lodash';
import * as process from 'node:process';
import { resolve } from 'path';
import { getAntdLocale } from './antd';
import { getCronLocale } from './cron';
import { getCronstrueLocale } from './cronstrue';
import _ from 'lodash';
async function getLang(ctx) {
const SystemSetting = ctx.db.getRepository('systemSettings');
@ -221,7 +221,14 @@ export class PluginClientServer extends Plugin {
const createModels = tabs
.map((x) => !modelsByRouteId[x.get('id')] && { desktopRouteId: x.get('id'), roleName })
.filter(Boolean);
return await repository.create({ values: createModels, transaction });
for (const values of createModels) {
await repository.firstOrCreate({
values,
filterKeys: ['desktopRouteId', 'roleName'],
transaction,
});
}
return;
}
if (action === 'remove') {

View File

@ -8,8 +8,8 @@
*/
import { Model, Transaction } from '@nocobase/database';
import { Plugin } from '@nocobase/server';
import PluginLocalizationServer from '@nocobase/plugin-localization';
import { Plugin } from '@nocobase/server';
import { tval } from '@nocobase/utils';
import _ from 'lodash';
@ -94,7 +94,14 @@ export class PluginMobileServer extends Plugin {
const createModels = tabs
.map((x) => !modelsByRouteId[x.get('id')] && { mobileRouteId: x.get('id'), roleName })
.filter(Boolean);
return await repository.create({ values: createModels, transaction });
for (const values of createModels) {
await repository.firstOrCreate({
values,
filterKeys: ['mobileRouteId', 'roleName'],
transaction,
});
}
return;
}
if (action === 'remove') {