Merge branch 'orm' into 'main'

Orm

See merge request fedeo/backend!7
This commit is contained in:
2025-12-10 07:40:46 +00:00

View File

@@ -373,13 +373,13 @@ export default async function resourceRoutes(server: FastifyInstance) {
// ------------------------------------------------------------- // -------------------------------------------------------------
// DETAIL (mit JOINS) // DETAIL (mit JOINS)
// ------------------------------------------------------------- // -------------------------------------------------------------
server.get("/resource/:resource/:id", async (req, reply) => { server.get("/resource/:resource/:id/:no_relations?", async (req, reply) => {
try { try {
const { id } = req.params as { id: string } const { id } = req.params as { id: string }
const tenantId = req.user?.tenant_id const tenantId = req.user?.tenant_id
if (!tenantId) return reply.code(400).send({ error: "No tenant selected" }) if (!tenantId) return reply.code(400).send({ error: "No tenant selected" })
const {resource} = req.params as { resource: string } const {resource, no_relations} = req.params as { resource: string, no_relations?: boolean }
const table = resourceConfig[resource].table const table = resourceConfig[resource].table
const projRows = await server.db const projRows = await server.db
@@ -402,6 +402,7 @@ export default async function resourceRoutes(server: FastifyInstance) {
...projRows[0] ...projRows[0]
} }
if(!no_relations) {
if(resourceConfig[resource].mtoLoad) { if(resourceConfig[resource].mtoLoad) {
for await (const relation of resourceConfig[resource].mtoLoad ) { for await (const relation of resourceConfig[resource].mtoLoad ) {
if(data[relation]) { if(data[relation]) {
@@ -416,6 +417,9 @@ export default async function resourceRoutes(server: FastifyInstance) {
data[relation] = await server.db.select().from(resourceConfig[relation].table).where(eq(resourceConfig[relation].table[resource.substring(0,resource.length - 1)],id)) data[relation] = await server.db.select().from(resourceConfig[relation].table).where(eq(resourceConfig[relation].table[resource.substring(0,resource.length - 1)],id))
} }
} }
}
return data return data
@@ -477,6 +481,7 @@ export default async function resourceRoutes(server: FastifyInstance) {
// UPDATE (inkl. Soft-Delete/Archive) // UPDATE (inkl. Soft-Delete/Archive)
server.put("/resource/:resource/:id", async (req, reply) => { server.put("/resource/:resource/:id", async (req, reply) => {
try {
const {resource, id} = req.params as { resource: string; id: string } const {resource, id} = req.params as { resource: string; id: string }
const body = req.body as Record<string, any> const body = req.body as Record<string, any>
@@ -529,6 +534,10 @@ export default async function resourceRoutes(server: FastifyInstance) {
}*/ }*/
return updated return updated
} catch (err) {
console.log("ERROR /resource/projects/:id", err)
}
}) })
} }