This commit is contained in:
2025-06-20 12:13:46 +05:00
parent cd61fc686b
commit 00c840abb7
9 changed files with 55 additions and 37 deletions
+6 -5
View File
@@ -29,13 +29,14 @@ export const filesController = new Elysia({ prefix: "/files" })
if (!ipAddress) return status(404, "Not Found");
return await got
const files = await got
.get(
`http://${ipAddress}:3001/files/${app.fileName}/${new Date(
createdAt
).getTime()}`
`http://${ipAddress}:3001/files/${
app.fileName
}/${createdAt.getTime()}`
)
.json();
.json<{ filename: string; size: string }>();
return files;
} catch (error) {
console.log((error as Error).message);
return status(500, "Internal Server Error");
+1 -1
View File
@@ -39,7 +39,7 @@ export const appsRelations = relations(appsTable, ({ one, many }) => ({
fields: [appsTable.companyId],
references: [companiesTable.id],
}),
servers: many(appsToServers),
appsToServers: many(appsToServers),
}));
export const appsToServers = pgTable(
+1 -1
View File
@@ -33,7 +33,7 @@ export const clientsRelations = relations(clientsTable, ({ one, many }) => ({
references: [companiesTable.id],
}),
sessions: many(sessionsTable),
managers: many(clientsToManagers),
clientsToManagers: many(clientsToManagers),
}));
export const clientsToManagers = pgTable(
+1 -1
View File
@@ -29,5 +29,5 @@ export const managersRelations = relations(managersTable, ({ one, many }) => ({
}),
tokens: many(tokensTable),
comments: many(commentsTable),
clients: many(clientsToManagers),
clientsToManagers: many(clientsToManagers),
}));
+1 -1
View File
@@ -49,5 +49,5 @@ export const serversRelations = relations(serversTable, ({ one, many }) => ({
references: [companiesTable.id],
}),
sessions: many(sessionsTable),
apps: many(appsToServers),
appsToServers: many(appsToServers),
}));
+13 -4
View File
@@ -28,10 +28,19 @@ async function createClient(
})
.returning();
await tx.insert(clientsToManagers).values({
clientId: newClient.id,
managerId: auth.managerId,
});
await tx
.insert(clientsToManagers)
.values({
clientId: newClient.id,
managerId: auth.managerId,
})
.onConflictDoUpdate({
target: [clientsToManagers.clientId, clientsToManagers.managerId],
set: {
clientId: newClient.id,
managerId: auth.managerId,
},
});
return newClient;
});
+30 -23
View File
@@ -13,31 +13,38 @@ async function getClients({
companyId: string;
}) {
try {
return await db.query.clientsTable.findMany({
where: and(
eq(clientsTable.companyId, companyId),
search
? or(
ilike(clientsTable.name, `%${search}%`),
ilike(clientsTable.email, `%${search}%`),
ilike(clientsTable.phone, `%${search}%`)
)
: undefined
),
limit,
with: {
managers: { with: { manager: { columns: { password: false } } } },
sessions: {
with: {
manager: { columns: { password: false } },
app: true,
comments: { with: { manager: { columns: { password: false } } } },
server: true,
client: true,
return (
await db.query.clientsTable.findMany({
where: and(
eq(clientsTable.companyId, companyId),
search
? or(
ilike(clientsTable.name, `%${search}%`),
ilike(clientsTable.email, `%${search}%`),
ilike(clientsTable.phone, `%${search}%`)
)
: undefined
),
limit,
with: {
clientsToManagers: {
with: { manager: { columns: { password: false } } },
},
sessions: {
with: {
manager: { columns: { password: false } },
app: true,
comments: { with: { manager: { columns: { password: false } } } },
server: true,
client: true,
},
},
},
},
});
})
).map(({ clientsToManagers, ...client }) => ({
...client,
managers: clientsToManagers.map(({ manager }) => manager),
}));
} catch (error) {
console.log((error as Error).message);
return status(500, "Internal Server Error");
+1
View File
@@ -17,6 +17,7 @@ export async function getComments(sessionId: string, managerId: string) {
id: true,
},
},
session: true,
},
orderBy: desc(commentsTable.createdAt),
});
+1 -1
View File
@@ -52,7 +52,7 @@ export default async function getServers(
},
},
},
apps: { with: { app: true } },
appsToServers: { with: { app: true } },
}
: undefined),
},