This commit is contained in:
2025-09-02 19:11:05 +02:00
parent 7c4272ffe9
commit dc385b8422
3 changed files with 40 additions and 4 deletions

View File

@@ -475,14 +475,13 @@ export default async function resourceRoutes(server: FastifyInstance) {
.select(select || dataTypes[resource].supabaseSelectWithInformation)
.eq("tenant", req.user.tenant_id)
.eq("archived", false)
const sorted =sortData(data,sort,asc === "true" ? true : false)
if (error) {
console.log(error)
return reply.code(400).send({ error: error.message });
}
const sorted =sortData(data,sort,asc === "true" ? true : false)
return sorted;
});
@@ -493,9 +492,11 @@ export default async function resourceRoutes(server: FastifyInstance) {
}
const { resource, id, with_information } = req.params as { resource: string; id: string, with_information: boolean };
const {select } = req.query as { select?: string }
// @ts-ignore
const { data, error } = await server.supabase.from(resource).select(with_information ? dataTypes[resource].supabaseSelectWithInformation : "*")
const { data, error } = await server.supabase.from(resource).select(select ? select : (with_information ? dataTypes[resource].supabaseSelectWithInformation : "*"))
.eq("id", id)
.eq("tenant", req.user.tenant_id)
.eq("archived", false) // nur aktive holen

View File

@@ -0,0 +1,33 @@
import {FastifyInstance} from "fastify";
import {sortData} from "../utils/sort";
export default async function resourceRoutesSpecial(server: FastifyInstance) {
// Liste
server.get("/resource-special/:resource", async (req, reply) => {
if (!req.user?.tenant_id) {
return reply.code(400).send({ error: "No tenant selected" });
}
const { resource } = req.params as { resource: string };
if(!["accounts","units","countrys"].includes(resource)) return reply.code(400).send({ error: "No corrected special resource selected" });
const {select, sort, asc } = req.query as { select?: string, sort?: string, asc?: string }
console.log(select, sort, asc)
const { data, error } = await server.supabase
.from(resource)
//@ts-ignore
.select(select || "*")
if (error) {
console.log(error)
return reply.code(400).send({ error: error.message });
}
const sorted =sortData(data,sort,asc === "true" ? true : false)
return sorted;
});
}