forked from yoone/API
1
0
Fork 0

feat(adapter): 公开映射方法以支持统一接口调用

将各适配器中的私有映射方法改为公开,并在接口中定义统一方法签名
修改webhook控制器以使用适配器映射方法处理订单数据
This commit is contained in:
zhuotianyuan 2026-01-07 11:54:34 +08:00
parent 5261011daa
commit f54b3c3617
1 changed files with 10 additions and 27 deletions

View File

@ -181,17 +181,11 @@ export class WebhookController {
console.log('Unhandled event:', topic);
}
return {
code: 200,
success: true,
message: 'Webhook processed successfully',
};
} else {
return {
code: 403,
success: false,
message: 'Webhook verification failed',
};
return {
code: 200,
success: true,
message: 'Webhook processed successfully',
};
}
} catch (error) {
console.log(error);
@ -207,23 +201,10 @@ export class WebhookController {
@Query('signature') signature: string,
@Headers() header: any
) {
console.log(`webhook shoppy`, siteIdStr, body, header)
const topic = header['x-oemsaas-event-type'];
// const source = header['x-oemsaas-shop-domain'];
// const source = header['x-oemsaas-shop-domain'];
const siteId = Number(siteIdStr);
const bodys = new UnifiedOrderDTO();
Object.assign(bodys, body);
// 从数据库获取站点配置
const site = await this.siteService.get(siteId, true);
// if (!site || !source?.includes(site.websiteUrl)) {
if (!site) {
console.log('domain not match');
return {
code: HttpStatus.BAD_REQUEST,
success: false,
message: 'domain not match',
};
}
if (!signature) {
return {
@ -239,6 +220,7 @@ export class WebhookController {
// .createHmac('sha256', this.secret)
// .update(rawBody)
// .digest('base64');
const adapter = await this.siteApiService.getAdapter(siteId);
try {
if (this.secret === signature) {
switch (topic) {
@ -251,7 +233,8 @@ export class WebhookController {
break;
case 'orders/create':
case 'orders/update':
await this.orderService.syncSingleOrder(siteId, bodys);
const order = adapter.mapOrder(body)
await this.orderService.syncSingleOrder(siteId, order);
break;
case 'orders/delete':
break;