@wishcbg/bobcode
Version:
基於店家同步功能的需求,讓店家能夠在不同的店家之間同步各項功能設定,並且能夠檢視各項功能的異動情況。 規劃出一套店家設定即程式碼的機制,讓店家能夠以 config file (.sac) 來定義各項功能設定,並且能夠還原店家各項功能設定。 暫且稱這個機制為「Settings as Code」「店家設定即程式碼」。
66 lines (65 loc) • 3.21 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ShopPointResourceSchema = exports.shopPointResourceSettingSchema = void 0;
const zod_1 = require("zod");
const shopPointWalletExpirationType = ['year', 'none'];
const shopPointTypes = ['basic', 'external'];
exports.shopPointResourceSettingSchema = zod_1.z.object({
name: zod_1.z.string().max(255).default('點數').describe('點數名稱'),
unitName: zod_1.z.string().max(255).default('點').describe('點數單位'),
daysUntilExpiration: zod_1.z.number().int().min(1).optional().describe('點數有效天數'),
annualSettlementDate: zod_1.z.string().describe('年度到期日'),
daysDiffExpirationNotify: zod_1.z.number().int().min(1).max(60).describe('到期通知發送天數'),
type: zod_1.z.enum(shopPointWalletExpirationType).describe('點數錢包到期類型'),
moduleType: zod_1.z.enum(shopPointTypes).default('basic').describe('模組類型'),
feature: zod_1.z.object({
findPointWalletBalance: zod_1.z.boolean().default(true).describe('查詢餘額'),
findPointWalletRecord: zod_1.z.boolean().default(true).describe('查詢記錄'),
addPointWalletRecord: zod_1.z.boolean().default(true).describe('新增'),
usePointWalletRecord: zod_1.z.boolean().default(true).describe('使用'),
}).optional().describe('功能設定'),
shopCustomModuleLogicId: zod_1.z.string().optional().describe('第三方模組 ID'),
}).describe('點數參數設定');
// 改成export一個 config 而不是class
exports.ShopPointResourceSchema = {
// —— 基本欄位
resourceType: 'shopPoint',
resourceName: '點數參數設定',
resourceSettingSchema: exports.shopPointResourceSettingSchema,
// —— 關聯
relationScope: 'shop',
relationType: 'multi',
relationResources: [
{
resourceType: 'shopCustomModule',
settingSchemaField: 'shopCustomModuleLogicId',
logicIdToResourceIdNewField: 'shopCustomModuleId',
relationType: 'single',
},
],
// —— apply API path
applySingleUpdateApiPath: null,
applyCreateApiPath: '/:shopId/shopPoint',
applyUpdateApiPath: '/:shopId/shopPoint/key/:shopPointKey',
applyDestroyApiPath: '/:shopId/shopPoint/:resourceId',
// —— apply API body transform
applyUpdateApiBodyTransform: async (pathParams, body, bobApi) => {
const { shopId, resourceId, } = pathParams;
const { data: shopPointList } = await bobApi.getExtraInfo(`/${shopId}/shopPoint/list`);
const shopPoint = shopPointList.find((item) => item.id === resourceId);
if (!shopPoint) {
throw new Error('找不到該店家點數服務設定');
}
body.shopCustomModuleLogicId;
return {
apiPath: `/${shopId}/shopPoint/key/${shopPoint.key}`,
apiBody: {
name: body.name,
unitName: body.unitName,
daysUntilExpiration: body.daysUntilExpiration,
annualSettlementDate: body.annualSettlementDate,
daysDiffExpirationNotify: body.daysDiffExpirationNotify,
}
};
}
};