Skip to content
This repository has been archived by the owner on Jul 30, 2021. It is now read-only.

Commit

Permalink
fix(model): returns invalid date if not present (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
douglasduteil committed Nov 16, 2020
1 parent f6584c6 commit 474f401
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
17 changes: 12 additions & 5 deletions packages/api/src/database/config.ts
@@ -1,16 +1,23 @@
import * as Knex from "knex";
import { join } from "path";
import { Model } from "objection";

export default () => {
const knexConnection = Knex(
require(process.env.KNEXFILE || "../../knexfile")
);
const config = process.env.KNEXFILE
? // tslint:disable-next-line: no-var-requires
require(process.env.KNEXFILE)
: // tslint:disable-next-line: no-var-requires
require(join(__dirname, "..", "..", "knexfile"));
const knexConnection = Knex(config);
Model.knex(knexConnection);
};

const aggregatorDatabase = Knex(
// tslint:disable-next-line: no-var-requires
require(process.env.KNEXFILE_AGGREGATOR || "../../knexfile-aggregator")
process.env.KNEXFILE_AGGREGATOR
? // tslint:disable-next-line: no-var-requires
require(process.env.KNEXFILE_AGGREGATOR)
: // tslint:disable-next-line: no-var-requires
require(join(__dirname, "..", "..", "knexfile"))
);

export { aggregatorDatabase };
11 changes: 9 additions & 2 deletions packages/api/src/model/dossier-record.model.ts
Expand Up @@ -102,8 +102,15 @@ export const hasExpired = (dossier: DossierRecord): boolean => {

export const getDateDebutAPTValue = (doc: DossierRecord) =>
getPrivateFieldValue(doc, "Date de début APT");
export const getDateFinAPTValue = (doc: DossierRecord) =>
getPrivateFieldValue(doc, "Date de fin APT");
export const getDateFinAPTValue = (doc: DossierRecord) => {
try {
return getPrivateFieldValue(doc, "Date de fin APT");
} catch (error) {
// Throwing here means that it's not present...
return "";
}
};

export const getPrenomValue = (doc: DossierRecord) => {
try {
return getPublicFieldValue(doc, "Prénom");
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Expand Up @@ -1890,6 +1890,11 @@
dependencies:
"@types/yargs-parser" "*"

"@vercel/ncc@^0.25.1":
version "0.25.1"
resolved "https://registry.yarnpkg.com/@vercel/ncc/-/ncc-0.25.1.tgz#a4aacdb508ac496fc0c63a3c3203d700a619cc0e"
integrity sha512-dGecC5+1wLof1MQpey4+6i2KZv4Sfs6WfXkl9KfO32GED4ZPiKxRfvtGPjbjZv0IbqMl6CxtcV1RotXYfd5SSA==

"@zkochan/cmd-shim@^3.1.0":
version "3.1.0"
resolved "https://registry.yarnpkg.com/@zkochan/cmd-shim/-/cmd-shim-3.1.0.tgz#2ab8ed81f5bb5452a85f25758eb9b8681982fd2e"
Expand Down

0 comments on commit 474f401

Please sign in to comment.