u
This commit is contained in:
@@ -32,14 +32,18 @@ export default function createUnderParent(provider) {
|
||||
* @param {number} input.googleAuthId - The id of the Google auth user.
|
||||
* @param {number} input.parentId - The id of the parent category.
|
||||
* @param {string} input.name - The article name.
|
||||
* @param {boolean|number} [input.track_stock=true] - Whether inventory stock is tracked.
|
||||
* @param {object} [tx] - Optional transaction to run within.
|
||||
* @returns {Promise<{id: number, parentId: number, name: string, sku: string}>} The created article.
|
||||
* @returns {Promise<{id: number, parentId: number, name: string, sku: string, track_stock: boolean}>} The created article.
|
||||
*
|
||||
* @example
|
||||
* const article = await store.article.createUnderParent({ googleAuthId: 42, parentId: 5, name: 'Cola' });
|
||||
* // => { id, parentId, name, sku }
|
||||
* // => { id, parentId, name, sku, track_stock }
|
||||
*/
|
||||
return async ({ googleAuthId, parentId, name }, tx) => {
|
||||
return async ({ googleAuthId, parentId, name, track_stock, trackStock }, tx) => {
|
||||
const rawTrack = track_stock ?? trackStock;
|
||||
const finalTrackStock = rawTrack == null ? 1 : (rawTrack ? 1 : 0);
|
||||
|
||||
const runCreate = async (runner) => {
|
||||
const { companyId, languageId, companyuserId } = await access(
|
||||
googleAuthId,
|
||||
@@ -59,6 +63,7 @@ export default function createUnderParent(provider) {
|
||||
unitId,
|
||||
unitamount: 1,
|
||||
weight: 0,
|
||||
trackStock: finalTrackStock,
|
||||
});
|
||||
} catch (err) {
|
||||
if (isUniqueConstraintError(err)) {
|
||||
@@ -92,6 +97,7 @@ export default function createUnderParent(provider) {
|
||||
parentId,
|
||||
name,
|
||||
sku,
|
||||
track_stock: Boolean(finalTrackStock),
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user