This commit is contained in:
seb
2026-10-08 12:44:53 +02:00
parent 79a1b72292
commit e2e7f8d566
11 changed files with 172 additions and 21 deletions

View File

@@ -167,6 +167,12 @@ export function register(app, basePath = '') {
* description: Category ID under which to create the article
* name:
* type: string
* desc:
* type: string
* description: Article description text/HTML
* seo:
* type: string
* description: SEO text
* track_stock:
* type: boolean
* description: Whether to track inventory stock (defaults to true)
@@ -215,7 +221,7 @@ export function register(app, basePath = '') {
* $ref: '#/components/schemas/Error'
*/
app.post(`${basePath}/article`, async (req, res) => {
const rawParent = req.body?.categoryId ?? req.body?.parentId;
const rawParent = req.body?.categoryId;
if (rawParent === undefined || rawParent === null) {
return res.status(400).json({ error: 'categoryId is required' });
}
@@ -229,7 +235,7 @@ export function register(app, basePath = '') {
return res.status(400).json({ error: 'name is required' });
}
const rawTrack = req.body?.track_stock ?? req.body?.trackStock;
const rawTrack = req.body?.track_stock;
if (rawTrack !== undefined && typeof rawTrack !== 'boolean' && rawTrack !== 0 && rawTrack !== 1) {
return res.status(400).json({ error: 'Invalid track_stock' });
}
@@ -237,12 +243,15 @@ export function register(app, basePath = '') {
const customSku = typeof req.body?.sku === 'string' && req.body.sku.trim() ? req.body.sku.trim() : undefined;
try {
const desc = req.body?.desc;
const created = await db.createUnderParent({
googleAuthId: req.user.id,
parentId,
name,
track_stock,
sku: customSku,
desc: desc !== undefined ? desc : undefined,
seo: req.body?.seo !== undefined ? req.body.seo : undefined,
});
emitArticlesSignal(req);
const article = {
@@ -438,6 +447,12 @@ export function register(app, basePath = '') {
* properties:
* name:
* type: string
* desc:
* type: string
* description: Article description text/HTML
* seo:
* type: string
* description: SEO text
* unitamount:
* type: number
* description: Must be finite and `> 0`
@@ -672,12 +687,23 @@ export function register(app, basePath = '') {
}
if (Object.prototype.hasOwnProperty.call(body, 'track_stock')) {
patch.track_stock = body.track_stock;
} else if (Object.prototype.hasOwnProperty.call(body, 'trackStock')) {
patch.track_stock = body.trackStock;
}
if (Object.prototype.hasOwnProperty.call(body, 'desc')) {
patch.desc = body.desc;
}
if (Object.prototype.hasOwnProperty.call(body, 'seo')) {
patch.seo = body.seo;
}
if (!('name' in patch) && !('unitamount' in patch) && !('unitSi' in patch) && !('track_stock' in patch)) {
return res.status(400).json({ error: 'name, unitamount, unitSi, or track_stock is required' });
if (
!('name' in patch) &&
!('unitamount' in patch) &&
!('unitSi' in patch) &&
!('track_stock' in patch) &&
!('desc' in patch) &&
!('seo' in patch)
) {
return res.status(400).json({ error: 'name, unitamount, unitSi, track_stock, desc, or seo is required' });
}
try {
@@ -1443,7 +1469,7 @@ export function register(app, basePath = '') {
return res.status(400).json({ error: skuParsed.error });
}
const raw = req.body?.track_stock ?? req.body?.trackStock;
const raw = req.body?.track_stock;
if (raw === undefined || (typeof raw !== 'boolean' && raw !== 0 && raw !== 1)) {
return res.status(400).json({ error: 'Invalid track_stock' });
}
@@ -1783,7 +1809,7 @@ export function register(app, basePath = '') {
if (typeof isParent !== 'boolean') {
return res.status(400).json({ error: 'isParent boolean is required' });
}
const attributeNameId = req.body?.attributeNameId ?? req.body?.parentAttributeNameId;
const attributeNameId = req.body?.attributeNameId;
try {
const result = await db.toggleParent(req.user.id, parsed.sku, {