This commit is contained in:
seb
2026-09-29 17:29:13 +02:00
parent ae5d5cc6f8
commit 30820ba8c7
14 changed files with 69 additions and 36 deletions

View File

@@ -22,8 +22,9 @@ export default function create(provider) {
* @param {object} input - The property name input.
* @param {string} input.name - The property name.
* @param {number} [input.sort] - Optional sort order.
* @param {boolean} [input.exclusive=false] - Whether values are mutually exclusive on an article.
* @param {object} [tx] - Optional transaction.
* @returns {Promise<{id: number, name: string, sort: number}>}
* @returns {Promise<{id: number, name: string, sort: number, exclusive: boolean}>}
*/
return async (googleAuthId, input = {}, tx) => {
const name = input.name?.trim();
@@ -40,13 +41,16 @@ export default function create(provider) {
sort = next.rows[0].sort;
}
const exclusive = Boolean(input.exclusive) ? 1 : 0;
const result = await runner.query(createSql, {
companyId,
name,
sort,
exclusive,
});
const id = result.rows[0]?.id ?? result.insertId;
return { id, name, sort };
return { id, name, sort, exclusive: Boolean(exclusive) };
};
}

View File

@@ -12,7 +12,7 @@ export default function list(provider) {
*
* @param {number} googleAuthId - The id of the Google auth user.
* @param {object} [tx] - Optional transaction.
* @returns {Promise<Array<{id: number, name: string, sort: number}>>}
* @returns {Promise<Array<{id: number, name: string, sort: number, exclusive: boolean}>>}
*/
return async (googleAuthId, tx) => {
const { companyId } = await access(googleAuthId, tx);
@@ -21,6 +21,7 @@ export default function list(provider) {
id: row.id,
name: row.name,
sort: row.sort,
exclusive: Boolean(row.exclusive),
}));
};
}

View File

@@ -23,8 +23,9 @@ export default function update(provider) {
* @param {object} input - Update patch.
* @param {string} [input.name] - New name.
* @param {number} [input.sort] - New sort.
* @param {boolean} [input.exclusive] - New exclusive flag.
* @param {object} [tx] - Optional transaction.
* @returns {Promise<{id: number, name: string, sort: number}>}
* @returns {Promise<{id: number, name: string, sort: number, exclusive: boolean}>}
*/
return async (googleAuthId, id, input = {}, tx) => {
if (!id || !Number.isInteger(Number(id))) {
@@ -44,14 +45,16 @@ export default function update(provider) {
throw new Error('Name required');
}
const sort = input.sort !== undefined && Number.isInteger(input.sort) ? input.sort : existing.rows[0].sort;
const exclusive = input.exclusive !== undefined ? (Boolean(input.exclusive) ? 1 : 0) : existing.rows[0].exclusive;
await runner.query(updateSql, {
id,
companyId,
name,
sort,
exclusive,
});
return { id, name, sort };
return { id, name, sort, exclusive: Boolean(exclusive) };
};
}