feat: add institution support for code gen and grouping
This commit is contained in:
parent
2a6cb6ddc0
commit
da372dc6fd
2 changed files with 27 additions and 6 deletions
|
|
@ -930,8 +930,10 @@ model EmployeeOtherInfo {
|
|||
}
|
||||
|
||||
model Institution {
|
||||
id String @id @default(cuid())
|
||||
name String
|
||||
id String @id @default(cuid())
|
||||
code String
|
||||
group String // Use for grouping, but not use relation
|
||||
name String
|
||||
|
||||
address String
|
||||
addressEN String
|
||||
|
|
|
|||
|
|
@ -27,6 +27,8 @@ function globalAllow(user: RequestWithUser["user"]) {
|
|||
type InstitutionPayload = {
|
||||
name: string;
|
||||
|
||||
code: string;
|
||||
|
||||
addressEN: string;
|
||||
address: string;
|
||||
soi?: string | null;
|
||||
|
|
@ -69,17 +71,34 @@ export class InstitutionController extends Controller {
|
|||
|
||||
@Get("{institutionId}")
|
||||
@Security("keycloak")
|
||||
async getInstitution(@Path() institutionId: string) {
|
||||
async getInstitution(@Path() institutionId: string, @Query() group?: string) {
|
||||
return await prisma.institution.findFirst({
|
||||
where: { id: institutionId },
|
||||
where: { id: institutionId, group },
|
||||
});
|
||||
}
|
||||
|
||||
@Post()
|
||||
@Security("keycloak")
|
||||
async createInstitution(@Body() body: InstitutionPayload) {
|
||||
return await prisma.institution.create({
|
||||
data: body,
|
||||
return await prisma.$transaction(async (tx) => {
|
||||
const last = await tx.runningNo.upsert({
|
||||
where: {
|
||||
key: `INST_${body.code}`,
|
||||
},
|
||||
create: {
|
||||
key: `INST_${body.code}`,
|
||||
value: 1,
|
||||
},
|
||||
update: { value: { increment: 1 } },
|
||||
});
|
||||
|
||||
return await tx.institution.create({
|
||||
data: {
|
||||
...body,
|
||||
code: `${body.code}${last.value.toString().padStart(5, "0")}`,
|
||||
group: body.code,
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue