-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e1e6d33
commit 473f529
Showing
8 changed files
with
130 additions
and
75 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
source/SIL.AppBuilder.Portal/common/databaseProxy/OrganizationProductDefinitions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import prisma from '../prisma.js'; | ||
|
||
export async function updateOrganizationProductDefinitions( | ||
orgId: number, | ||
productDefinitions: number[] | ||
) { | ||
const old = ( | ||
await prisma.organizationProductDefinitions.findMany({ | ||
where: { | ||
OrganizationId: orgId | ||
} | ||
}) | ||
).map((x) => x.ProductDefinitionId); | ||
const newEntries = productDefinitions.filter( | ||
(productDefinition) => !old.includes(productDefinition) | ||
); | ||
const removeEntries = old.filter( | ||
(productDefinition) => !productDefinitions.includes(productDefinition) | ||
); | ||
await prisma.$transaction([ | ||
prisma.organizationProductDefinitions.deleteMany({ | ||
where: { | ||
OrganizationId: orgId, | ||
ProductDefinitionId: { | ||
in: removeEntries | ||
} | ||
} | ||
}), | ||
prisma.organizationProductDefinitions.createMany({ | ||
data: newEntries.map((store) => ({ | ||
OrganizationId: orgId, | ||
ProductDefinitionId: store | ||
})) | ||
}) | ||
]); | ||
} |
29 changes: 29 additions & 0 deletions
29
source/SIL.AppBuilder.Portal/common/databaseProxy/OrganizationStores.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import prisma from '../prisma.js'; | ||
|
||
export async function updateOrganizationStores(orgId: number, stores: number[]) { | ||
const old = ( | ||
await prisma.organizationStores.findMany({ | ||
where: { | ||
OrganizationId: orgId | ||
} | ||
}) | ||
).map((x) => x.StoreId); | ||
const newEntries = stores.filter((store) => !old.includes(store)); | ||
const removeEntries = old.filter((store) => !stores.includes(store)); | ||
await prisma.$transaction([ | ||
prisma.organizationStores.deleteMany({ | ||
where: { | ||
OrganizationId: orgId, | ||
StoreId: { | ||
in: removeEntries | ||
} | ||
} | ||
}), | ||
prisma.organizationStores.createMany({ | ||
data: newEntries.map((store) => ({ | ||
OrganizationId: orgId, | ||
StoreId: store | ||
})) | ||
}) | ||
]); | ||
} |
37 changes: 37 additions & 0 deletions
37
source/SIL.AppBuilder.Portal/common/databaseProxy/UserRoles.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import prisma from '../prisma.js'; | ||
import { RoleId } from '../public/prisma.js'; | ||
|
||
export async function setUserRolesForOrganization( | ||
userId: number, | ||
organizationId: number, | ||
roles: RoleId[] | ||
) { | ||
const old = ( | ||
await prisma.userRoles.findMany({ | ||
where: { | ||
UserId: userId, | ||
OrganizationId: organizationId | ||
} | ||
}) | ||
).map((r) => r.RoleId); | ||
const remove = old.filter((role) => !roles.includes(role)); | ||
const add = roles.filter((role) => !old.includes(role)); | ||
await prisma.$transaction([ | ||
prisma.userRoles.deleteMany({ | ||
where: { | ||
UserId: userId, | ||
OrganizationId: organizationId, | ||
RoleId: { | ||
in: remove | ||
} | ||
} | ||
}), | ||
prisma.userRoles.createMany({ | ||
data: add.map((r) => ({ | ||
UserId: userId, | ||
OrganizationId: organizationId, | ||
RoleId: r | ||
})) | ||
}) | ||
]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters