2022-01-24 15:32:27 +01:00
|
|
|
export const buildUserEndpoints = API => ({
|
|
|
|
/**
|
|
|
|
* Gets a list of users in the current tenant.
|
|
|
|
*/
|
|
|
|
getUsers: async () => {
|
|
|
|
return await API.get({
|
|
|
|
url: "/api/global/users",
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets a list of users in the current tenant.
|
2022-06-30 16:39:26 +02:00
|
|
|
* @param {string} page The page to retrieve
|
|
|
|
* @param {string} search The starts with string to search username/email by.
|
2022-01-24 15:32:27 +01:00
|
|
|
*/
|
2022-07-06 17:09:05 +02:00
|
|
|
searchUsers: async ({ page, email, appId } = {}) => {
|
2022-06-30 16:39:26 +02:00
|
|
|
const opts = {}
|
|
|
|
if (page) {
|
|
|
|
opts.page = page
|
|
|
|
}
|
2022-07-06 17:09:05 +02:00
|
|
|
if (email) {
|
|
|
|
opts.email = email
|
|
|
|
}
|
|
|
|
if (appId) {
|
|
|
|
opts.appId = appId
|
2022-06-30 16:39:26 +02:00
|
|
|
}
|
2022-06-30 17:01:14 +02:00
|
|
|
return await API.post({
|
|
|
|
url: `/api/global/users/search`,
|
|
|
|
body: opts,
|
2022-06-29 20:11:00 +02:00
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a single user by ID.
|
|
|
|
*/
|
|
|
|
getUser: async userId => {
|
|
|
|
return await API.get({
|
|
|
|
url: `/api/global/users/${userId}`,
|
2022-01-24 15:32:27 +01:00
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a user for an app.
|
|
|
|
* @param user the user to create
|
|
|
|
*/
|
|
|
|
createAppUser: async user => {
|
|
|
|
return await API.post({
|
|
|
|
url: "/api/users/metadata",
|
|
|
|
body: user,
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates the current user metadata.
|
|
|
|
* @param metadata the metadata to save
|
|
|
|
*/
|
|
|
|
updateOwnMetadata: async metadata => {
|
|
|
|
return await API.post({
|
|
|
|
url: "/api/users/metadata/self",
|
|
|
|
body: metadata,
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates an admin user.
|
|
|
|
* @param adminUser the admin user to create
|
|
|
|
*/
|
|
|
|
createAdminUser: async adminUser => {
|
|
|
|
return await API.post({
|
|
|
|
url: "/api/global/users/init",
|
|
|
|
body: adminUser,
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates or updates a user in the current tenant.
|
|
|
|
* @param user the new user to create
|
|
|
|
*/
|
|
|
|
saveUser: async user => {
|
|
|
|
return await API.post({
|
|
|
|
url: "/api/global/users",
|
|
|
|
body: user,
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
2022-07-11 16:29:39 +02:00
|
|
|
/**
|
|
|
|
* Creates multiple users.
|
|
|
|
* @param users the array of user objects to create
|
|
|
|
*/
|
2022-07-25 17:58:30 +02:00
|
|
|
createUsers: async ({ users, groups }) => {
|
2022-07-11 16:29:39 +02:00
|
|
|
return await API.post({
|
2022-07-25 17:58:30 +02:00
|
|
|
url: "/api/global/users/bulkCreate",
|
2022-07-11 16:29:39 +02:00
|
|
|
body: {
|
|
|
|
users,
|
|
|
|
groups,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
2022-01-24 15:32:27 +01:00
|
|
|
/**
|
|
|
|
* Deletes a user from the curernt tenant.
|
|
|
|
* @param userId the ID of the user to delete
|
|
|
|
*/
|
|
|
|
deleteUser: async userId => {
|
|
|
|
return await API.delete({
|
|
|
|
url: `/api/global/users/${userId}`,
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
2022-07-13 16:46:10 +02:00
|
|
|
/**
|
|
|
|
* Deletes multiple users
|
|
|
|
* @param userId the ID of the user to delete
|
|
|
|
*/
|
|
|
|
deleteUsers: async userIds => {
|
|
|
|
return await API.post({
|
|
|
|
url: `/api/global/users/bulkDelete`,
|
|
|
|
body: {
|
|
|
|
userIds,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
2022-01-24 15:32:27 +01:00
|
|
|
/**
|
|
|
|
* Invites a user to the current tenant.
|
|
|
|
* @param email the email address to send the invitation to
|
|
|
|
* @param builder whether the user should be a global builder
|
|
|
|
* @param admin whether the user should be a global admin
|
|
|
|
*/
|
|
|
|
inviteUser: async ({ email, builder, admin }) => {
|
|
|
|
return await API.post({
|
|
|
|
url: "/api/global/users/invite",
|
|
|
|
body: {
|
|
|
|
email,
|
|
|
|
userInfo: {
|
|
|
|
admin: admin ? { global: true } : undefined,
|
|
|
|
builder: builder ? { global: true } : undefined,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
2022-07-05 10:21:59 +02:00
|
|
|
/**
|
|
|
|
* Invites multiple users to the current tenant.
|
2022-08-03 16:16:26 +02:00
|
|
|
* @param users An array of users to invite
|
2022-07-05 10:21:59 +02:00
|
|
|
*/
|
2022-08-03 16:16:26 +02:00
|
|
|
inviteUsers: async users => {
|
2022-07-05 10:21:59 +02:00
|
|
|
return await API.post({
|
|
|
|
url: "/api/global/users/inviteMultiple",
|
2022-08-03 16:16:26 +02:00
|
|
|
body: users.map(user => ({
|
|
|
|
email: user.email,
|
2022-07-05 10:21:59 +02:00
|
|
|
userInfo: {
|
2022-08-03 16:16:26 +02:00
|
|
|
admin: user.admin ? { global: true } : undefined,
|
|
|
|
builder: user.admin || user.builder ? { global: true } : undefined,
|
2022-07-05 10:21:59 +02:00
|
|
|
},
|
2022-08-03 16:16:26 +02:00
|
|
|
})),
|
2022-07-05 10:21:59 +02:00
|
|
|
})
|
|
|
|
},
|
|
|
|
|
2022-01-24 15:32:27 +01:00
|
|
|
/**
|
2022-02-16 14:13:40 +01:00
|
|
|
* Accepts an invite to join the platform and creates a user.
|
2022-01-24 15:32:27 +01:00
|
|
|
* @param inviteCode the invite code sent in the email
|
|
|
|
* @param password the password for the newly created user
|
|
|
|
*/
|
2022-02-16 14:13:40 +01:00
|
|
|
acceptInvite: async ({ inviteCode, password }) => {
|
2022-01-24 15:32:27 +01:00
|
|
|
return await API.post({
|
|
|
|
url: "/api/global/users/invite/accept",
|
|
|
|
body: {
|
|
|
|
inviteCode,
|
|
|
|
password,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
},
|
2022-07-29 14:10:00 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Accepts an invite to join the platform and creates a user.
|
|
|
|
* @param inviteCode the invite code sent in the email
|
|
|
|
* @param password the password for the newly created user
|
|
|
|
*/
|
|
|
|
getUserCountByApp: async ({ appId }) => {
|
|
|
|
return await API.get({
|
|
|
|
url: `/api/global/users/count/${appId}`,
|
|
|
|
})
|
|
|
|
},
|
2022-01-24 15:32:27 +01:00
|
|
|
})
|