u
This commit is contained in:
@@ -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<Array<{id: number, googleAuthId: number, email: string, role: 'admin'|'user'}>>` — The company users ordered by email.
|
||||
`Promise<Array<{id: number, googleAuthId: number, email: string, picture: string|null, role: 'admin'|'user'}>>` — 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**
|
||||
|
||||
|
||||
6
API.md
6
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<number>`
|
||||
- `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<void>`
|
||||
- `getByEmail(email: string, tx?: object): Promise<Array<number>>`
|
||||
- `list(googleAuthId: number, tx?: object): Promise<Array<{id: number, googleAuthId: number, email: string, role: 'admin'|'user'}>>`
|
||||
- `list(googleAuthId: number, tx?: object): Promise<Array<{id: number, googleAuthId: number, email: string, picture: string|null, role: 'admin'|'user'}>>`
|
||||
- `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}>`
|
||||
|
||||
@@ -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 = `
|
||||
|
||||
@@ -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 };
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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<Array<{id: number, googleAuthId: number, email: string, role: 'admin'|'user'}>>} The company users ordered by email.
|
||||
* @returns {Promise<Array<{id: number, googleAuthId: number, email: string, picture: string|null, role: 'admin'|'user'}>>} The company users ordered by email.
|
||||
* @throws {Error} 'Not authorized' / 'No company selected'
|
||||
*
|
||||
* @example
|
||||
|
||||
@@ -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 };
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user