fix: pnpm i without db connection
This commit is contained in:
@@ -12,16 +12,22 @@ export enum AuthProviderStatus {
|
|||||||
* (ConfigModule will set the environment variables in the process)
|
* (ConfigModule will set the environment variables in the process)
|
||||||
*/
|
*/
|
||||||
export async function loadInfraConfiguration() {
|
export async function loadInfraConfiguration() {
|
||||||
const prisma = new PrismaService();
|
try {
|
||||||
|
const prisma = new PrismaService();
|
||||||
|
|
||||||
const infraConfigs = await prisma.infraConfig.findMany();
|
const infraConfigs = await prisma.infraConfig.findMany();
|
||||||
|
|
||||||
let environmentObject: Record<string, any> = {};
|
let environmentObject: Record<string, any> = {};
|
||||||
infraConfigs.forEach((infraConfig) => {
|
infraConfigs.forEach((infraConfig) => {
|
||||||
environmentObject[infraConfig.name] = infraConfig.value;
|
environmentObject[infraConfig.name] = infraConfig.value;
|
||||||
});
|
});
|
||||||
|
|
||||||
return { INFRA: environmentObject };
|
return { INFRA: environmentObject };
|
||||||
|
} catch (error) {
|
||||||
|
// Prisma throw error if 'Can't reach at database server' OR 'Table does not exist'
|
||||||
|
// We're not throwing error here because we want to allow the app to run 'pnpm install'
|
||||||
|
return { INFRA: {} };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
import { mockDeep, mockReset } from 'jest-mock-extended';
|
import { mockDeep, mockReset } from 'jest-mock-extended';
|
||||||
import { PrismaService } from 'src/prisma/prisma.service';
|
import { PrismaService } from 'src/prisma/prisma.service';
|
||||||
import { InfraConfigService } from './infra-config.service';
|
import { InfraConfigService } from './infra-config.service';
|
||||||
import { InfraConfigEnum } from 'src/types/InfraConfig';
|
import {
|
||||||
|
InfraConfigEnum,
|
||||||
|
InfraConfigEnumForClient,
|
||||||
|
} from 'src/types/InfraConfig';
|
||||||
import { INFRA_CONFIG_NOT_FOUND, INFRA_CONFIG_UPDATE_FAILED } from 'src/errors';
|
import { INFRA_CONFIG_NOT_FOUND, INFRA_CONFIG_UPDATE_FAILED } from 'src/errors';
|
||||||
import { ConfigService } from '@nestjs/config';
|
import { ConfigService } from '@nestjs/config';
|
||||||
import * as helper from './helper';
|
import * as helper from './helper';
|
||||||
@@ -68,7 +71,7 @@ describe('InfraConfigService', () => {
|
|||||||
|
|
||||||
describe('get', () => {
|
describe('get', () => {
|
||||||
it('should get the infra config', async () => {
|
it('should get the infra config', async () => {
|
||||||
const name = InfraConfigEnum.GOOGLE_CLIENT_ID;
|
const name = InfraConfigEnumForClient.GOOGLE_CLIENT_ID;
|
||||||
const value = 'true';
|
const value = 'true';
|
||||||
|
|
||||||
mockPrisma.infraConfig.findUniqueOrThrow.mockResolvedValueOnce({
|
mockPrisma.infraConfig.findUniqueOrThrow.mockResolvedValueOnce({
|
||||||
@@ -84,7 +87,7 @@ describe('InfraConfigService', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should pass correct params to prisma findUnique', async () => {
|
it('should pass correct params to prisma findUnique', async () => {
|
||||||
const name = InfraConfigEnum.GOOGLE_CLIENT_ID;
|
const name = InfraConfigEnumForClient.GOOGLE_CLIENT_ID;
|
||||||
|
|
||||||
await infraConfigService.get(name);
|
await infraConfigService.get(name);
|
||||||
|
|
||||||
@@ -95,7 +98,7 @@ describe('InfraConfigService', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should throw an error if the infra config does not exist', async () => {
|
it('should throw an error if the infra config does not exist', async () => {
|
||||||
const name = InfraConfigEnum.GOOGLE_CLIENT_ID;
|
const name = InfraConfigEnumForClient.GOOGLE_CLIENT_ID;
|
||||||
|
|
||||||
mockPrisma.infraConfig.findUniqueOrThrow.mockRejectedValueOnce('null');
|
mockPrisma.infraConfig.findUniqueOrThrow.mockRejectedValueOnce('null');
|
||||||
|
|
||||||
|
|||||||
@@ -105,7 +105,10 @@ export class InfraConfigService implements OnModuleInit {
|
|||||||
stopApp();
|
stopApp();
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.code === 'P2021') {
|
if (error.code === 'P1001') {
|
||||||
|
// Prisma error code for 'Can't reach at database server'
|
||||||
|
// We're not throwing error here because we want to allow the app to run 'pnpm install'
|
||||||
|
} else if (error.code === 'P2021') {
|
||||||
// Prisma error code for 'Table does not exist'
|
// Prisma error code for 'Table does not exist'
|
||||||
throwErr(DATABASE_TABLE_NOT_EXIST);
|
throwErr(DATABASE_TABLE_NOT_EXIST);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user