From 26f21cd7ac21b9136922690e5b740a0f3f8d5820 Mon Sep 17 00:00:00 2001 From: seb Date: Mon, 2 Nov 2026 00:51:18 +0100 Subject: [PATCH] u --- API.companyuser.md | 6 +++--- API.md | 6 +++--- src/providers/mssql/queries/companyuser.js | 14 +++++++++----- src/store/companyuser/addByEmail.js | 4 ++-- src/store/companyuser/list.js | 2 +- src/store/companyuser/setRole.js | 4 ++-- 6 files changed, 20 insertions(+), 16 deletions(-) diff --git a/API.companyuser.md b/API.companyuser.md index fcc5274..11044d9 100644 --- a/API.companyuser.md +++ b/API.companyuser.md @@ -48,7 +48,7 @@ Adds an existing Google auth user to the admin's selected company. The added use **Returns** -`Promise<{id: number, googleAuthId: number, email: string, role: 'admin'|'user'}>` — The created company user. +`Promise<{id: number, googleAuthId: number, email: string, picture: string|null, role: 'admin'|'user'}>` — The created company user. **Throws** @@ -122,7 +122,7 @@ Lists the members of the admin's selected company. **Returns** -`Promise>` — The company users ordered by email. +`Promise>` — The company users ordered by email. **Throws** @@ -220,7 +220,7 @@ Changes the role of a member of the admin's selected company. **Returns** -`Promise<{id: number, googleAuthId: number, role: 'admin'|'user'}>` — The updated company user. +`Promise<{id: number, googleAuthId: number, email: string, picture: string|null, role: 'admin'|'user'}>` — The updated company user. **Throws** diff --git a/API.md b/API.md index 1d5de4e..0dcded5 100644 --- a/API.md +++ b/API.md @@ -83,14 +83,14 @@ The store is exposed as a `LibDashStore` instance (see `src/index.js`). Each met - [companyuser](API.companyuser.md) - `add(companyId: number, googleAuthId: number, role?: 'admin'|'user', tx?: object): Promise` - - `addByEmail(googleAuthId: number, input: {email: string, role?: 'admin'|'user'}, tx?: object): Promise<{id: number, googleAuthId: number, email: string, role: 'admin'|'user'}>` + - `addByEmail(googleAuthId: number, input: {email: string, role?: 'admin'|'user'}, tx?: object): Promise<{id: number, googleAuthId: number, email: string, picture: string|null, role: 'admin'|'user'}>` - `delete(id: number, tx?: object): Promise` - `getByEmail(email: string, tx?: object): Promise>` - - `list(googleAuthId: number, tx?: object): Promise>` + - `list(googleAuthId: number, tx?: object): Promise>` - `remove(googleAuthId: number, id: number, tx?: object): Promise<{id: number, googleAuthId: number}>` - `requireAdmin(googleAuthId: number, tx?: object): Promise<{companyId: number, companyuserId: number, role: string}>` - `roles(role: unknown): 'admin'|'user'` - - `setRole(googleAuthId: number, id: number, role: 'admin'|'user', tx?: object): Promise<{id: number, googleAuthId: number, role: 'admin'|'user'}>` + - `setRole(googleAuthId: number, id: number, role: 'admin'|'user', tx?: object): Promise<{id: number, googleAuthId: number, email: string, picture: string|null, role: 'admin'|'user'}>` - `withTransaction(): void` - [company](API.company.md) - `addHistory(googleAuthId: number, input: {text?: string}, tx?: object): Promise<{id: number, companyuserId: number|null, date: string, text: string}>` diff --git a/src/providers/mssql/queries/companyuser.js b/src/providers/mssql/queries/companyuser.js index 0c43227..938a953 100644 --- a/src/providers/mssql/queries/companyuser.js +++ b/src/providers/mssql/queries/companyuser.js @@ -34,6 +34,7 @@ SELECT cu.id, cu.google_auth_id AS googleAuthId, ga.email, + ga.picture, cu.role FROM companyuser cu INNER JOIN google_auth ga ON ga.id = cu.google_auth_id @@ -43,11 +44,14 @@ ORDER BY ga.email export const GET_IN_COMPANY = ` SELECT - id, - google_auth_id AS googleAuthId, - role -FROM companyuser -WHERE id = @id AND company_id = @companyId + cu.id, + cu.google_auth_id AS googleAuthId, + ga.email, + ga.picture, + cu.role +FROM companyuser cu +INNER JOIN google_auth ga ON ga.id = cu.google_auth_id +WHERE cu.id = @id AND cu.company_id = @companyId `; export const GET_MEMBERSHIP = ` diff --git a/src/store/companyuser/addByEmail.js b/src/store/companyuser/addByEmail.js index ad40bc1..e9b1d6c 100644 --- a/src/store/companyuser/addByEmail.js +++ b/src/store/companyuser/addByEmail.js @@ -21,7 +21,7 @@ export default function addByEmail(provider) { * @param {number} googleAuthId - The id of the acting Google auth user (must be admin of the selected company). * @param {{email: string, role?: 'admin'|'user'}} input - Email of the existing user and role (default 'user'). * @param {object} [tx] - Optional transaction to run within. - * @returns {Promise<{id: number, googleAuthId: number, email: string, role: 'admin'|'user'}>} The created company user. + * @returns {Promise<{id: number, googleAuthId: number, email: string, picture: string|null, role: 'admin'|'user'}>} The created company user. * @throws {Error} 'Not authorized', 'Invalid email', 'Invalid role', 'User not found', 'User already in company' * * @example @@ -41,6 +41,6 @@ export default function addByEmail(provider) { const result = await runner.query(addSql, { companyId, googleAuthId: auth.id, role }); const id = result.rows[0]?.id ?? result.insertId; - return { id, googleAuthId: auth.id, email: auth.email, role }; + return { id, googleAuthId: auth.id, email: auth.email, picture: auth.picture ?? null, role }; }); } diff --git a/src/store/companyuser/list.js b/src/store/companyuser/list.js index 25ba95b..c500a18 100644 --- a/src/store/companyuser/list.js +++ b/src/store/companyuser/list.js @@ -12,7 +12,7 @@ export default function list(provider) { * * @param {number} googleAuthId - The id of the Google auth user (must be admin of the selected company). * @param {object} [tx] - Optional transaction to run within. - * @returns {Promise>} The company users ordered by email. + * @returns {Promise>} The company users ordered by email. * @throws {Error} 'Not authorized' / 'No company selected' * * @example diff --git a/src/store/companyuser/setRole.js b/src/store/companyuser/setRole.js index f40ab8e..dce3099 100644 --- a/src/store/companyuser/setRole.js +++ b/src/store/companyuser/setRole.js @@ -26,7 +26,7 @@ export default function setRole(provider) { * @param {number} id - The company user id. * @param {'admin'|'user'} role - The new role. * @param {object} [tx] - Optional transaction to run within. - * @returns {Promise<{id: number, googleAuthId: number, role: 'admin'|'user'}>} The updated company user. + * @returns {Promise<{id: number, googleAuthId: number, email: string, picture: string|null, role: 'admin'|'user'}>} The updated company user. * @throws {Error} 'Not authorized', 'Invalid role', 'Company user not found', 'Cannot demote the last admin' * * @example @@ -46,6 +46,6 @@ export default function setRole(provider) { } await runner.query(setSql, { id, role }); - return { id: member.id, googleAuthId: member.googleAuthId, role }; + return { id: member.id, googleAuthId: member.googleAuthId, email: member.email, picture: member.picture ?? null, role }; }); }