Skip to content

Commit

Permalink
rework templating
Browse files Browse the repository at this point in the history
  • Loading branch information
eike-hass committed Jul 19, 2024
1 parent 24caf0a commit bd02d5b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
32 changes: 32 additions & 0 deletions backend/src/webapp/webapp.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,38 @@ export class WebAppService {
},
};

const walkObj = (obj) => {
if (!obj) return;
for (const [key, val] of Object.entries(obj)) {
if (typeof val === 'object') {
walkObj(val); // recursively call the function
}
if (typeof val === 'string' && val.startsWith('**TEMPLATE')) {
// TODO: extract template function
switch (val) {
case '**TEMPLATE_DATENOW':
obj[key] = new Date().toISOString();
break;

case '**TEMPLATE_BIRTHDAY':
const start = new Date(1955, 0, 1);
const end = new Date(2012, 0, 1);

obj[key] = new Date(
start.getTime() +
Math.random() * (end.getTime() - start.getTime()),
).toISOString();
break;

default:
break;
}
}
}
};

walkObj(credential_template);

this.logger.debug('requesting', credential_template);
return this.identityService.create(
issuer,
Expand Down
4 changes: 2 additions & 2 deletions shared/credentials/CitizenCredential.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
"VerifiableCredential",
"CitizenCredential"
],
"issuanceDate": "2017-10-22T12:23:48Z",
"issuanceDate": "**TEMPLATE_DATENOW",
"issuer": "PLACEHOLDER",
"credentialSubject": {
"id": "PLACEHOLDER",
"firstName": "Ben",
"lastName": "Utzer",
"date": "Date.now()",
"date": "**TEMPLATE_BIRTHDAY",
"nationality": "german",
"birthplace": "Musterstadt",
"country": "Germany",
Expand Down
2 changes: 1 addition & 1 deletion shared/credentials/CompanyCredential.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"VerifiableCredential",
"CompanyCredential"
],
"issuanceDate": "2017-10-22T12:23:48Z",
"issuanceDate": "**TEMPLATE_DATENOW",
"issuer": "PLACEHOLDER",
"credentialSubject": {
"id": "PLACEHOLDER"
Expand Down

0 comments on commit bd02d5b

Please sign in to comment.