Changes
This commit is contained in:
@@ -11,6 +11,7 @@ import authPlugin from "./plugins/auth";
|
||||
import adminRoutes from "./routes/admin";
|
||||
import corsPlugin from "./plugins/cors";
|
||||
import resourceRoutes from "./routes/resources";
|
||||
import resourceRoutesSpecial from "./routes/resourcesSpecial";
|
||||
import fastifyCookie from "@fastify/cookie";
|
||||
import historyRoutes from "./routes/history";
|
||||
import fileRoutes from "./routes/files";
|
||||
@@ -48,6 +49,7 @@ async function main() {
|
||||
await subApp.register(tenantRoutes);
|
||||
await subApp.register(adminRoutes);
|
||||
await subApp.register(resourceRoutes);
|
||||
await subApp.register(resourceRoutesSpecial);
|
||||
await subApp.register(historyRoutes);
|
||||
await subApp.register(fileRoutes);
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
33
src/routes/resourcesSpecial.ts
Normal file
33
src/routes/resourcesSpecial.ts
Normal 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;
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user