Merge pull request 'feature/43-postal_from_env' (#46) from feature/43-postal_from_env into dev
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: #46 closes #43
This commit is contained in:
commit
cdc90b0770
3
.env.ci
3
.env.ci
@ -5,4 +5,5 @@ DB_PORT=unused
|
|||||||
DB_USER=unused
|
DB_USER=unused
|
||||||
DB_PASSWORD=bla
|
DB_PASSWORD=bla
|
||||||
DB_NAME=./test.sqlite
|
DB_NAME=./test.sqlite
|
||||||
NODE_ENV=dev
|
NODE_ENV=dev
|
||||||
|
POSTALCODE_COUNTRYCODE=null
|
@ -5,4 +5,5 @@ DB_PORT=bla
|
|||||||
DB_USER=bla
|
DB_USER=bla
|
||||||
DB_PASSWORD=bla
|
DB_PASSWORD=bla
|
||||||
DB_NAME=bla
|
DB_NAME=bla
|
||||||
NODE_ENV=production
|
NODE_ENV=production
|
||||||
|
POSTALCODE_COUNTRYCODE=null
|
@ -1,10 +1,13 @@
|
|||||||
import { config as configDotenv } from 'dotenv';
|
import { config as configDotenv } from 'dotenv';
|
||||||
|
import ValidatorJS from 'validator';
|
||||||
|
|
||||||
configDotenv();
|
configDotenv();
|
||||||
export const config = {
|
export const config = {
|
||||||
internal_port: parseInt(process.env.APP_PORT) || 4010,
|
internal_port: parseInt(process.env.APP_PORT) || 4010,
|
||||||
development: process.env.NODE_ENV === "production",
|
development: process.env.NODE_ENV === "production",
|
||||||
jwt_secret: process.env.JWT_SECRET || "secretjwtsecret",
|
jwt_secret: process.env.JWT_SECRET || "secretjwtsecret",
|
||||||
phone_validation_countrycode: process.env.PHONE_COUNTRYCODE || "ZZ"
|
phone_validation_countrycode: process.env.PHONE_COUNTRYCODE || "ZZ",
|
||||||
|
postalcode_validation_countrycode: getPostalCodeLocale()
|
||||||
}
|
}
|
||||||
let errors = 0
|
let errors = 0
|
||||||
if (typeof config.internal_port !== "number") {
|
if (typeof config.internal_port !== "number") {
|
||||||
@ -19,4 +22,13 @@ if (config.phone_validation_countrycode.length !== 2) {
|
|||||||
if (typeof config.development !== "boolean") {
|
if (typeof config.development !== "boolean") {
|
||||||
errors++
|
errors++
|
||||||
}
|
}
|
||||||
|
function getPostalCodeLocale(): any {
|
||||||
|
try {
|
||||||
|
const stringArray: String[] = ValidatorJS.isPostalCodeLocales;
|
||||||
|
let index = stringArray.indexOf(process.env.POSTALCODE_COUNTRYCODE);
|
||||||
|
return ValidatorJS.isPostalCodeLocales[index];
|
||||||
|
} catch (error) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
export let e = errors
|
export let e = errors
|
@ -1,4 +1,5 @@
|
|||||||
import { IsNotEmpty, IsOptional, IsPostalCode, IsString } from 'class-validator';
|
import { IsNotEmpty, IsOptional, IsPostalCode, IsString } from 'class-validator';
|
||||||
|
import { config } from '../../config';
|
||||||
import { Address } from '../entities/Address';
|
import { Address } from '../entities/Address';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -35,7 +36,7 @@ export class CreateAddress {
|
|||||||
*/
|
*/
|
||||||
@IsString()
|
@IsString()
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
@IsPostalCode("DE")
|
@IsPostalCode(config.postalcode_validation_countrycode)
|
||||||
postalcode: string;
|
postalcode: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -6,6 +6,7 @@ import {
|
|||||||
IsString
|
IsString
|
||||||
} from "class-validator";
|
} from "class-validator";
|
||||||
import { Column, Entity, OneToMany, PrimaryGeneratedColumn } from "typeorm";
|
import { Column, Entity, OneToMany, PrimaryGeneratedColumn } from "typeorm";
|
||||||
|
import { config } from '../../config';
|
||||||
import { Participant } from "./Participant";
|
import { Participant } from "./Participant";
|
||||||
import { RunnerOrganisation } from "./RunnerOrganisation";
|
import { RunnerOrganisation } from "./RunnerOrganisation";
|
||||||
|
|
||||||
@ -52,12 +53,11 @@ export class Address {
|
|||||||
/**
|
/**
|
||||||
* The address's postal code.
|
* The address's postal code.
|
||||||
* This will get checked against the postal code syntax for the configured country.
|
* This will get checked against the postal code syntax for the configured country.
|
||||||
* TODO: Implement the config option.
|
|
||||||
*/
|
*/
|
||||||
@Column()
|
@Column()
|
||||||
@IsString()
|
@IsString()
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
@IsPostalCode("DE")
|
@IsPostalCode(config.postalcode_validation_countrycode)
|
||||||
postalcode: string;
|
postalcode: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user