generated from antfu/starter-ts
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5866109
commit 0c8779e
Showing
5 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export class FeedImg { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,50 @@ | ||
/** | ||
* @param {string} sku - SKU of the product | ||
* @param {number} deal_time - 预处理时间 默认2天 | ||
* @param {number} quantity - 数量 | ||
*/ | ||
export interface FeedQuantityData { sku: string, quantity: number, deal_time: number } | ||
|
||
export class FeedQuantity { | ||
sellerId: string | ||
list: FeedQuantityData[] | ||
constructor(sellerId: string, list: FeedQuantityData[]) { | ||
this.sellerId = sellerId | ||
this.list = list | ||
} | ||
|
||
main() { | ||
return { | ||
header: { | ||
sellerId: this.sellerId, | ||
version: '2.0', | ||
issueLocale: 'en_US', | ||
}, | ||
messages: this.genMessage(), | ||
} | ||
} | ||
|
||
genMessage() { | ||
return this.list.map((item, idx) => { | ||
return { | ||
messageId: idx + 1, | ||
sku: item.sku, | ||
operationType: 'PATCH', | ||
productType: 'PRODUCT', | ||
patches: [ | ||
{ | ||
op: 'replace', | ||
path: '/attributes/fulfillment_availability', | ||
value: [ | ||
{ | ||
fulfillment_channel_code: 'DEFAULT', | ||
quantity: item.quantity, | ||
lead_time_to_ship_max_days: item.deal_time || 2, | ||
}, | ||
], | ||
}, | ||
], | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './feed/img' | ||
export * from './feed/price' | ||
export * from './feed/quantity' | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export class ListingImg {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { describe, expect, it } from 'vitest' | ||
import { FeedQuantity } from '../../src/index' | ||
|
||
describe('should', () => { | ||
const t1 = new FeedQuantity('sellerId', [{ sku: 'sku-1', quantity: 100, deal_time: 3 }]) | ||
it('t1 message', () => { | ||
const obj = t1.main() | ||
console.log(obj) | ||
expect(obj.messages.length).toEqual(1) | ||
}) | ||
}) |