From df6ef3aaa04bc26f354b69fa49eb8398df880fd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rado=C5=A1?= Date: Fri, 27 Jan 2023 18:52:23 +0100 Subject: [PATCH] Fixes coollabsio/coolify#884 --- .../src/routes/api/v1/applications/handlers.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/apps/api/src/routes/api/v1/applications/handlers.ts b/apps/api/src/routes/api/v1/applications/handlers.ts index dd669ca33..384cbdfa9 100644 --- a/apps/api/src/routes/api/v1/applications/handlers.ts +++ b/apps/api/src/routes/api/v1/applications/handlers.ts @@ -117,7 +117,7 @@ export async function getImages(request: FastifyRequest) { export async function cleanupUnconfiguredApplications(request: FastifyRequest) { try { const teamId = request.user.teamId; - let applications = await prisma.application.findMany({ + const applications = await prisma.application.findMany({ where: { teams: { some: { id: teamId === '0' ? undefined : teamId } } }, include: { settings: true, destinationDocker: true, teams: true } }); @@ -167,7 +167,7 @@ export async function getApplicationStatus(request: FastifyRequest) { try { const { id } = request.params; const { teamId } = request.user; - let payload = []; + const payload = []; const application: any = await getApplicationFromDB(id, teamId); if (application?.destinationDockerId) { if (application.buildPack === 'compose') { @@ -565,7 +565,7 @@ export async function restartApplication( const { id } = request.params; const { imageId = null } = request.body; const { teamId } = request.user; - let application: any = await getApplicationFromDB(id, teamId); + const application: any = await getApplicationFromDB(id, teamId); if (application?.destinationDockerId) { const buildId = cuid(); const { id: dockerId, network } = application.destinationDocker; @@ -737,7 +737,7 @@ export async function deleteApplication( where: { id }, include: { destinationDocker: true, teams: true } }); - if (!application.teams.find((team) => team.id === teamId) || teamId !== '0') { + if (teamId === '0' || !application.teams.some((team) => team.id === teamId)) { throw { status: 403, message: 'You are not allowed to delete this application.' }; } if (application?.destinationDocker?.id && application.destinationDocker?.network) { @@ -1377,7 +1377,7 @@ export async function restartPreview( try { const { id, pullmergeRequestId } = request.params; const { teamId } = request.user; - let application: any = await getApplicationFromDB(id, teamId); + const application: any = await getApplicationFromDB(id, teamId); if (application?.destinationDockerId) { const buildId = cuid(); const { id: dockerId, network } = application.destinationDocker; @@ -1692,7 +1692,7 @@ export async function getBuildIdLogs(request: FastifyRequest) { try { await fs.stat(file); } catch (error) { - let logs = await prisma.buildLog.findMany({ + const logs = await prisma.buildLog.findMany({ where: { buildId, time: { gt: sequence } }, orderBy: { time: 'asc' } }); @@ -1708,9 +1708,9 @@ export async function getBuildIdLogs(request: FastifyRequest) { status: data?.status || 'queued' }; } - let fileLogs = (await fs.readFile(file)).toString(); - let decryptedLogs = await csv({ noheader: true }).fromString(fileLogs); - let logs = decryptedLogs + const fileLogs = (await fs.readFile(file)).toString(); + const decryptedLogs = await csv({ noheader: true }).fromString(fileLogs); + const logs = decryptedLogs .map((log) => { const parsed = { time: log['field1'],