58 lines
1.6 KiB
TypeScript
Raw Normal View History

2022-02-10 15:47:44 +01:00
import { getDomain } from '$lib/common';
import { prisma } from './common';
2022-02-10 15:47:44 +01:00
export async function isBranchAlreadyUsed({ repository, branch, id }) {
const application = await prisma.application.findUnique({
where: { id },
include: { gitSource: true }
});
return await prisma.application.findFirst({
where: { branch, repository, gitSource: { type: application.gitSource.type }, id: { not: id } }
});
}
export async function isDockerNetworkExists({ network }) {
return await prisma.destinationDocker.findFirst({ where: { network } });
}
2022-02-19 14:54:47 +01:00
export async function isSecretExists({ id, name, isPRMRSecret }) {
return await prisma.secret.findFirst({ where: { name, applicationId: id, isPRMRSecret } });
2022-02-10 15:47:44 +01:00
}
export async function isDomainConfigured({ id, fqdn }) {
const domain = getDomain(fqdn);
const nakedDomain = domain.replace('www.', '');
2022-02-10 15:47:44 +01:00
const foundApp = await prisma.application.findFirst({
where: {
OR: [
{ fqdn: { endsWith: `//${nakedDomain}` } },
{ fqdn: { endsWith: `//www.${nakedDomain}` } }
],
id: { not: id }
},
2022-02-10 15:47:44 +01:00
select: { fqdn: true }
});
const foundService = await prisma.service.findFirst({
where: {
OR: [
{ fqdn: { endsWith: `//${nakedDomain}` } },
{ fqdn: { endsWith: `//www.${nakedDomain}` } }
],
id: { not: id }
},
2022-02-10 15:47:44 +01:00
select: { fqdn: true }
});
const coolifyFqdn = await prisma.setting.findFirst({
where: {
OR: [
{ fqdn: { endsWith: `//${nakedDomain}` } },
{ fqdn: { endsWith: `//www.${nakedDomain}` } }
],
id: { not: id }
},
2022-02-10 15:47:44 +01:00
select: { fqdn: true }
});
if (foundApp || foundService || coolifyFqdn) return true;
return false;
}