upd
This commit is contained in:
@@ -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");
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -29,5 +29,5 @@ export const managersRelations = relations(managersTable, ({ one, many }) => ({
|
||||
}),
|
||||
tokens: many(tokensTable),
|
||||
comments: many(commentsTable),
|
||||
clients: many(clientsToManagers),
|
||||
clientsToManagers: many(clientsToManagers),
|
||||
}));
|
||||
|
||||
@@ -49,5 +49,5 @@ export const serversRelations = relations(serversTable, ({ one, many }) => ({
|
||||
references: [companiesTable.id],
|
||||
}),
|
||||
sessions: many(sessionsTable),
|
||||
apps: many(appsToServers),
|
||||
appsToServers: many(appsToServers),
|
||||
}));
|
||||
|
||||
@@ -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;
|
||||
});
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -17,6 +17,7 @@ export async function getComments(sessionId: string, managerId: string) {
|
||||
id: true,
|
||||
},
|
||||
},
|
||||
session: true,
|
||||
},
|
||||
orderBy: desc(commentsTable.createdAt),
|
||||
});
|
||||
|
||||
@@ -52,7 +52,7 @@ export default async function getServers(
|
||||
},
|
||||
},
|
||||
},
|
||||
apps: { with: { app: true } },
|
||||
appsToServers: { with: { app: true } },
|
||||
}
|
||||
: undefined),
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user