chore: clean up
This commit is contained in:
parent
4c28941bc2
commit
b6a5e3c41e
1 changed files with 5 additions and 8 deletions
|
|
@ -13,18 +13,10 @@ import {
|
|||
Security,
|
||||
Tags,
|
||||
} from "tsoa";
|
||||
import { RequestWithUser } from "../interfaces/user";
|
||||
import prisma from "../db";
|
||||
import { notFoundError } from "../utils/error";
|
||||
import { queryOrNot } from "../utils/relation";
|
||||
|
||||
const MANAGE_ROLES = ["system", "head_of_admin", "admin"];
|
||||
|
||||
function globalAllow(user: RequestWithUser["user"]) {
|
||||
const allowList = ["system", "head_of_admin"];
|
||||
return allowList.some((v) => user.roles?.includes(v));
|
||||
}
|
||||
|
||||
type InstitutionPayload = {
|
||||
name: string;
|
||||
|
||||
|
|
@ -49,6 +41,7 @@ type InstitutionPayload = {
|
|||
export class InstitutionController extends Controller {
|
||||
@Get()
|
||||
@Security("keycloak")
|
||||
@OperationId("getInstitutionList")
|
||||
async getInstitutionList(
|
||||
@Query() query: string = "",
|
||||
@Query() page: number = 1,
|
||||
|
|
@ -74,6 +67,7 @@ export class InstitutionController extends Controller {
|
|||
|
||||
@Get("{institutionId}")
|
||||
@Security("keycloak")
|
||||
@OperationId("getInstitution")
|
||||
async getInstitution(@Path() institutionId: string, @Query() group?: string) {
|
||||
return await prisma.institution.findFirst({
|
||||
where: { id: institutionId, group },
|
||||
|
|
@ -82,6 +76,7 @@ export class InstitutionController extends Controller {
|
|||
|
||||
@Post()
|
||||
@Security("keycloak")
|
||||
@OperationId("createInstitution")
|
||||
async createInstitution(@Body() body: InstitutionPayload) {
|
||||
return await prisma.$transaction(async (tx) => {
|
||||
const last = await tx.runningNo.upsert({
|
||||
|
|
@ -107,6 +102,7 @@ export class InstitutionController extends Controller {
|
|||
|
||||
@Put("{institutionId}")
|
||||
@Security("keycloak")
|
||||
@OperationId("updateInstitution")
|
||||
async updateInstitution(@Path() institutionId: string, @Body() body: InstitutionPayload) {
|
||||
return await prisma.institution.update({
|
||||
where: { id: institutionId },
|
||||
|
|
@ -116,6 +112,7 @@ export class InstitutionController extends Controller {
|
|||
|
||||
@Delete("{institutionId}")
|
||||
@Security("keycloak")
|
||||
@OperationId("deleteInstitution")
|
||||
async deleteInstitution(@Path() institutionId: string) {
|
||||
return await prisma.$transaction(async (tx) => {
|
||||
const record = await tx.institution.findFirst({
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue