MCPcopy Index your code
hub / github.com/Linen-dev/linen.dev / updateUserRole

Method updateUserRole

apps/web/services/users/users.ts:18–53  ·  view source on GitHub ↗
({
    userId,
    role,
  }: {
    userId: string;
    role: Roles;
  })

Source from the content-addressed store, hash-verified

16
17export default class UsersService {
18 static async updateUserRole({
19 userId,
20 role,
21 }: {
22 userId: string;
23 role: Roles;
24 }) {
25 const userToUpdate = await prisma.users.findUnique({
26 where: { id: userId },
27 });
28 if (!userToUpdate) {
29 throw 'user not found';
30 }
31
32 // the account it should have at least another owner
33 if (userToUpdate.role === Roles.OWNER && role !== Roles.OWNER) {
34 const anotherOwner = await prisma.users.findFirst({
35 where: {
36 accountsId: userToUpdate.accountsId,
37 role: Roles.OWNER,
38 NOT: {
39 id: userToUpdate.id,
40 },
41 },
42 });
43 if (!anotherOwner) {
44 throw 'the account need at least one owner';
45 }
46 }
47 return await prisma.users.update({
48 where: { id: userToUpdate.id },
49 data: {
50 role,
51 },
52 });
53 }
54 static async updateTenant({
55 authId,
56 accountId,

Callers 3

users.test.tsFile · 0.80
index.tsFile · 0.80
onChangeMemberFunction · 0.80

Calls 1

updateMethod · 0.45

Tested by

no test coverage detected