diff --git a/src/routes/resources/main.ts b/src/routes/resources/main.ts index 5f279fb..7d781bd 100644 --- a/src/routes/resources/main.ts +++ b/src/routes/resources/main.ts @@ -373,13 +373,13 @@ export default async function resourceRoutes(server: FastifyInstance) { // ------------------------------------------------------------- // DETAIL (mit JOINS) // ------------------------------------------------------------- - server.get("/resource/:resource/:id", async (req, reply) => { + server.get("/resource/:resource/:id/:no_relations?", async (req, reply) => { try { const { id } = req.params as { id: string } const tenantId = req.user?.tenant_id 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 projRows = await server.db @@ -402,20 +402,24 @@ export default async function resourceRoutes(server: FastifyInstance) { ...projRows[0] } - if(resourceConfig[resource].mtoLoad) { - for await (const relation of resourceConfig[resource].mtoLoad ) { - if(data[relation]) { - data[relation] = (await server.db.select().from(resourceConfig[relation + "s"].table).where(eq(resourceConfig[relation + "s"].table.id, data[relation])))[0] + if(!no_relations) { + if(resourceConfig[resource].mtoLoad) { + for await (const relation of resourceConfig[resource].mtoLoad ) { + if(data[relation]) { + data[relation] = (await server.db.select().from(resourceConfig[relation + "s"].table).where(eq(resourceConfig[relation + "s"].table.id, data[relation])))[0] + } + } + } + + if(resourceConfig[resource].mtmLoad) { + for await (const relation of resourceConfig[resource].mtmLoad ) { + console.log(relation) + data[relation] = await server.db.select().from(resourceConfig[relation].table).where(eq(resourceConfig[relation].table[resource.substring(0,resource.length - 1)],id)) } } } - if(resourceConfig[resource].mtmLoad) { - for await (const relation of resourceConfig[resource].mtmLoad ) { - console.log(relation) - data[relation] = await server.db.select().from(resourceConfig[relation].table).where(eq(resourceConfig[relation].table[resource.substring(0,resource.length - 1)],id)) - } - } + return data