u
This commit is contained in:
@@ -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) };
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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),
|
||||
}));
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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) };
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user