parent
ae34d1fab0
commit
5ca3c94afc
|
|
@ -78,8 +78,5 @@ export class MainConfiguration {
|
|||
}
|
||||
}
|
||||
);
|
||||
|
||||
const sites = this.app.getConfig('wpSite') || [];
|
||||
await this.siteService.syncFromConfig(sites);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,25 +11,6 @@ export class SiteService {
|
|||
@InjectEntityModel(Site)
|
||||
siteModel: Repository<Site>;
|
||||
|
||||
async syncFromConfig(sites: WpSite[] = []) {
|
||||
// 将配置中的 WpSite 同步到数据库 Site 表(用于一次性导入或初始化)
|
||||
for (const siteConfig of sites) {
|
||||
// 按站点名称查询是否已存在记录
|
||||
const exist = await this.siteModel.findOne({ where: { siteName: siteConfig.siteName } });
|
||||
// 将 WpSite 字段映射为 Site 实体字段
|
||||
const payload: Partial<Site> = {
|
||||
siteName: siteConfig.siteName,
|
||||
apiUrl: (siteConfig as any).wpApiUrl,
|
||||
consumerKey: (siteConfig as any).consumerKey,
|
||||
consumerSecret: (siteConfig as any).consumerSecret,
|
||||
type: 'woocommerce',
|
||||
};
|
||||
// 存在则更新,不存在则插入新记录
|
||||
if (exist) await this.siteModel.update({ id: exist.id }, payload);
|
||||
else await this.siteModel.insert(payload as Site);
|
||||
}
|
||||
}
|
||||
|
||||
async create(data: Partial<Site>) {
|
||||
// 创建新的站点记录
|
||||
await this.siteModel.insert(data as Site);
|
||||
|
|
|
|||
Loading…
Reference in New Issue