Vertragstypen für Änderungsanfragen pflegen
This commit is contained in:
1
backend/db/migrations/0036_allowed_contracttypes.sql
Normal file
1
backend/db/migrations/0036_allowed_contracttypes.sql
Normal file
@@ -0,0 +1 @@
|
||||
ALTER TABLE "contracts" ADD COLUMN "allowedContracttypes" jsonb DEFAULT '[]'::jsonb NOT NULL;
|
||||
@@ -246,6 +246,13 @@
|
||||
"when": 1778191200000,
|
||||
"tag": "0035_contract_history",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 35,
|
||||
"version": "7",
|
||||
"when": 1778194800000,
|
||||
"tag": "0036_allowed_contracttypes",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -52,6 +52,7 @@ export const contracts = pgTable(
|
||||
contracttype: bigint("contracttype", { mode: "number" }).references(
|
||||
() => contracttypes.id
|
||||
),
|
||||
allowedContracttypes: jsonb("allowedContracttypes").notNull().default([]),
|
||||
|
||||
bankingIban: text("bankingIban"),
|
||||
bankingBIC: text("bankingBIC"),
|
||||
|
||||
@@ -32,6 +32,7 @@ async function getPortalContract(server: FastifyInstance, req: any, contractId:
|
||||
tenant: contracts.tenant,
|
||||
customer: contracts.customer,
|
||||
contracttype: contracts.contracttype,
|
||||
allowedContracttypes: contracts.allowedContracttypes,
|
||||
archived: contracts.archived,
|
||||
})
|
||||
.from(contracts)
|
||||
@@ -121,6 +122,14 @@ export default async function portalContractRoutes(server: FastifyInstance) {
|
||||
return reply.code(400).send({ error: "Ungültiger Vertragstyp" })
|
||||
}
|
||||
|
||||
const allowedContracttypes = Array.isArray(contract.allowedContracttypes)
|
||||
? contract.allowedContracttypes.map((id) => Number(id)).filter((id) => Number.isInteger(id))
|
||||
: []
|
||||
|
||||
if (!allowedContracttypes.includes(requestedContracttype.id)) {
|
||||
return reply.code(400).send({ error: "Dieser Vertragstyp steht für diesen Vertrag nicht zur Auswahl" })
|
||||
}
|
||||
|
||||
const [currentContracttype] = contract.contracttype
|
||||
? await server.db
|
||||
.select({
|
||||
|
||||
Reference in New Issue
Block a user