Skip to content

Commit

Permalink
Merge branch 'main' into 17-retries
Browse files Browse the repository at this point in the history
  • Loading branch information
kennsippell committed Feb 12, 2024
2 parents b91cd88 + 033c353 commit d8d60bd
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 17 deletions.
24 changes: 24 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/dist/index.js",
"envFile": "${workspaceFolder}/.env"
},
{
"command": "npm test",
"name": "Run npm test",
"request": "launch",
"type": "node-terminal"
}
]
}
19 changes: 17 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cht-user-management",
"version": "1.0.9",
"version": "1.0.10",
"main": "dist/index.js",
"dependencies": {
"@fastify/autoload": "^5.8.0",
Expand All @@ -11,6 +11,7 @@
"@fastify/view": "^8.2.0",
"@types/jsonwebtoken": "^9.0.5",
"@types/lodash": "^4.14.201",
"@types/luxon": "^3.4.2",
"@types/node": "^20.8.8",
"@types/uuid": "^9.0.6",
"axios": "^1.5.1",
Expand All @@ -23,6 +24,7 @@
"libphonenumber-js": "^1.10.48",
"liquidjs": "^10.9.2",
"lodash": "^4.17.21",
"luxon": "^3.4.4",
"pino-pretty": "^10.2.3",
"typescript": "^5.2.2",
"uuid": "^9.0.1"
Expand Down
2 changes: 1 addition & 1 deletion src/config/chis-ug/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
{
"friendly_name": "Date of Birth",
"property_name": "date_of_birth",
"type": "name",
"type": "dob",
"required": true
},
{
Expand Down
15 changes: 8 additions & 7 deletions src/lib/validation.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Config, ContactProperty } from '../config';

import ValidatorString from './validator-string';
import ValidatorPhone from './validator-phone';
import ValidatorRegex from './validator-regex';
import ValidatorName from './validator-name';
import ValidatorGender from './validator-gender';
import Place from '../services/place';
import ValidatorSkip from './validator-skip';
import RemotePlaceResolver from './remote-place-resolver';
import { RemotePlace } from './cht-api';

import ValidatorDateOfBirth from './validator-dob';
import ValidatorGender from './validator-gender';
import ValidatorName from './validator-name';
import ValidatorPhone from './validator-phone';
import ValidatorRegex from './validator-regex';
import ValidatorSkip from './validator-skip';
import ValidatorString from './validator-string';

export type ValidationError = {
property_name: string;
Expand All @@ -33,6 +33,7 @@ const TypeValidatorMap: ValidatorMap = {
phone: new ValidatorPhone(),
none: new ValidatorSkip(),
gender: new ValidatorGender(),
dob: new ValidatorDateOfBirth(),
};

export class Validation {
Expand Down
32 changes: 32 additions & 0 deletions src/lib/validator-dob.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { DateTime } from 'luxon';
import { IValidator } from './validation';

export default class ValidatorDateOfBirth implements IValidator {
isValid(input: string) : boolean | string {
try {
const parsed = parse(input);
return parsed.isValid && parsed.diffNow('hours').hours <= 0;
} catch (e) {
return false;
}
}

format(input : string) : string {
const parsed = parse(input);
const asISODate = parsed.toISODate();
if (!asISODate) {
return input;
}

return asISODate;
}

get defaultError(): string {
return 'Not a valid Date of Birth (eg. 1990-02-26)';
}
}

const parse = (input: string) => {
const strippedInput = input.replace(/ /ig, '');
return DateTime.fromISO(strippedInput);
};
19 changes: 14 additions & 5 deletions src/public/app/view.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
integrity="sha384-FhXw7b6AlE/jyjlZH5iHa/tTe9EpJ1Y55RjcgPbjeWMskSxZt1v9qkxLJWNJaGni"
crossorigin="anonymous"></script>
<script src="https://unpkg.com/htmx.org/dist/ext/sse.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/css/bulma.min.css">
<link href="https://cdn.jsdelivr.net/npm/@creativebulma/[email protected]/dist/bulma-tooltip.min.css"
rel="stylesheet">
<link rel="stylesheet"
href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@24,400,0,0" />
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bulma-calendar.min.js"></script>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/css/bulma.min.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@creativebulma/[email protected]/dist/bulma-tooltip.min.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bulma-calendar.min.css" />
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@24,400,0,0" />

<style>
.material-symbols-outlined {
Expand All @@ -31,6 +32,14 @@
{% endif %}
</div>
</div>

<script type="text/javascript">
bulmaCalendar.attach('input[type="date"]', {
lang: 'en-US',
dateFormat: 'yyyy-MM-dd',
maxDate: new Date(),
});
</script>
</body>

</html>
2 changes: 1 addition & 1 deletion src/public/components/contact_type_property.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<div class="control">
<input
name="{{ prop_name }}"
type="text"
type="{% if include.prop.type == 'dob' %}date{% else %}text{% endif %}"
class="input"
{% if false and include.prop.type == 'regex' %} pattern="{{ include.prop.parameter }}" {% endif %}
{% if data[prop_name] %} value="{{ data[prop_name] }}" {% endif %}
Expand Down
7 changes: 7 additions & 0 deletions test/lib/validation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ const scenarios: Scenario[] = [
{ type: 'name', prop: 'Sam\'s CHU', propertyParameter: ['CHU', 'Comm Unit'], isValid: true, altered: 'Sam\'s' },
{ type: 'name', prop: 'Jonathan M.Barasa', isValid: true, altered: 'Jonathan M Barasa' },

{ type: 'dob', prop: '', isValid: false },
{ type: 'dob', prop: '2016/05/25', isValid: false },
{ type: 'dob', prop: 'May 25, 2016', isValid: false },
{ type: 'dob', prop: '2030-05-25', isValid: false },
{ type: 'dob', prop: '2016-05-25', isValid: true, altered: '2016-05-25' },
{ type: 'dob', prop: ' 20 16- 05- 25 ', isValid: true, altered: '2016-05-25' },

{ type: 'gender', prop: 'Man', isValid: true, altered: 'male' },
{ type: 'gender', prop: 'male', isValid: true, altered: 'male' },
{ type: 'gender', prop: 'F', isValid: true, altered: 'female' },
Expand Down

0 comments on commit d8d60bd

Please sign in to comment.