fix(plugins): seed all SuperAdmin khanegi setting keys into the store catalog
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -78,6 +78,16 @@ export const PLUGIN_CATALOG_SEED: Array<{
|
|||||||
titleFa: 'نمایش چت به کاربران',
|
titleFa: 'نمایش چت به کاربران',
|
||||||
description: 'نمایش چت پشتیبانی در اپ مشتری.',
|
description: 'نمایش چت پشتیبانی در اپ مشتری.',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
settingKey: 'has_landing',
|
||||||
|
titleFa: 'لندینگ وبسایت',
|
||||||
|
description: 'صفحهٔ لندینگ نسخهٔ خانگی.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
settingKey: 'permision__enabled',
|
||||||
|
titleFa: 'نمایش منوی مجوزها',
|
||||||
|
description: 'منوی مجوزها در ادمین و اپ.',
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
export function daysToPlanMonths(days: number): 1 | 3 | 6 | 12 {
|
export function daysToPlanMonths(days: number): 1 | 3 | 6 | 12 {
|
||||||
@@ -105,6 +115,8 @@ export function inferSettingKeyFromName(name: string): string | null {
|
|||||||
[/قلک/, 'enable_product_funds'],
|
[/قلک/, 'enable_product_funds'],
|
||||||
[/هشدار قیمت/, 'has_page_price_trigger'],
|
[/هشدار قیمت/, 'has_page_price_trigger'],
|
||||||
[/نمایش چت|چت به کاربر/, 'show_to_users_chat'],
|
[/نمایش چت|چت به کاربر/, 'show_to_users_chat'],
|
||||||
|
[/لندینگ/, 'has_landing'],
|
||||||
|
[/مجوز/, 'permision__enabled'],
|
||||||
];
|
];
|
||||||
for (const [re, key] of rules) {
|
for (const [re, key] of rules) {
|
||||||
if (re.test(n)) return key;
|
if (re.test(n)) return key;
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import { AdminNotifyService } from '../notifications/admin-notify.service';
|
|||||||
import { CentralSmsService } from '../notifications/central-sms.service';
|
import { CentralSmsService } from '../notifications/central-sms.service';
|
||||||
import { ProgramSettingsService } from '../program-settings/program-settings.service';
|
import { ProgramSettingsService } from '../program-settings/program-settings.service';
|
||||||
import { PLUGIN_STORE_SETTING_KEY } from '../program-settings/runtime-setting-keys';
|
import { PLUGIN_STORE_SETTING_KEY } from '../program-settings/runtime-setting-keys';
|
||||||
|
import { DEPLOY_SETTING_CATALOG_KEYS } from '../program-settings/deploy-setting-catalog-keys';
|
||||||
import {
|
import {
|
||||||
addIranMonths,
|
addIranMonths,
|
||||||
addIranPlanExpiry,
|
addIranPlanExpiry,
|
||||||
@@ -80,16 +81,26 @@ export class PluginStoreService implements OnModuleInit, OnModuleDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async seedCatalog() {
|
async seedCatalog() {
|
||||||
for (const row of PLUGIN_CATALOG_SEED) {
|
const templates = await this.prisma.settingTemplate.findMany({
|
||||||
|
where: { key: { in: [...DEPLOY_SETTING_CATALOG_KEYS] } },
|
||||||
|
select: { key: true, titleFa: true, description: true },
|
||||||
|
});
|
||||||
|
const templateByKey = new Map(templates.map((row) => [row.key, row]));
|
||||||
|
const seedByKey = new Map(PLUGIN_CATALOG_SEED.map((row) => [row.settingKey, row]));
|
||||||
|
const keys = new Set([...DEPLOY_SETTING_CATALOG_KEYS, ...seedByKey.keys()]);
|
||||||
|
|
||||||
|
for (const settingKey of keys) {
|
||||||
const existing = await this.prisma.pluginCatalogItem.findUnique({
|
const existing = await this.prisma.pluginCatalogItem.findUnique({
|
||||||
where: { settingKey: row.settingKey },
|
where: { settingKey },
|
||||||
});
|
});
|
||||||
if (existing) continue;
|
if (existing) continue;
|
||||||
|
const seed = seedByKey.get(settingKey);
|
||||||
|
const template = templateByKey.get(settingKey);
|
||||||
await this.prisma.pluginCatalogItem.create({
|
await this.prisma.pluginCatalogItem.create({
|
||||||
data: {
|
data: {
|
||||||
settingKey: row.settingKey,
|
settingKey,
|
||||||
titleFa: row.titleFa,
|
titleFa: seed?.titleFa || template?.titleFa || settingKey,
|
||||||
description: row.description,
|
description: seed?.description || template?.description || '',
|
||||||
inStore: true,
|
inStore: true,
|
||||||
prices: {
|
prices: {
|
||||||
create: PLUGIN_STORE_DURATIONS.map((durationDays) => ({
|
create: PLUGIN_STORE_DURATIONS.map((durationDays) => ({
|
||||||
|
|||||||
Reference in New Issue
Block a user