Skip to content

Commit

Permalink
feat(api): add script to save a new legal document version
Browse files Browse the repository at this point in the history
  • Loading branch information
P-Jeremy committed Dec 11, 2024
1 parent 79d7276 commit 0755aed
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions api/scripts/legal-documents/add-new-legal-document-version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import 'dotenv/config';

import * as legalDocumentRepository from '../../src/legal-documents/infrastructure/repositories/legal-document.repository.js';
import { Script } from '../../src/shared/application/scripts/script.js';
import { ScriptRunner } from '../../src/shared/application/scripts/script-runner.js';

export class AddNewLegalDocumentVersion extends Script {
constructor() {
super({
description: 'Add a new legal document version.',
permanent: true,
options: {
type: {
type: 'string',
describe: 'Type of document (ex: "TOS", "PDP")',
demandOption: true,
},
service: {
type: 'string',
describe: 'Associated service (ex: "pix-app", "pix-orga",...)',
demandOption: true,
},
versionAt: {
type: 'string',
describe: 'Version date of the legal document, format "YYYY-MM-DD", (ex: "2020-02-27")',
demandOption: true,
},
},
});
}

async handle({ options, logger }) {
let { type, service, versionAt } = options;

type = type?.trim();
service = service?.trim();
versionAt = versionAt?.trim();

logger.info(`Adding new legal document for type:${type}, service:${service}, versionAt:${versionAt}`);

try {
await legalDocumentRepository.createLegalDocument({ type, service, versionAt });
} catch (error) {
logger.error(error);
} finally {
logger.info(
`New legal document for type:${type}, service:${service}, versionAt:${versionAt} added successfully.`,
);
}
}
}

await ScriptRunner.execute(import.meta.url, AddNewLegalDocumentVersion);

0 comments on commit 0755aed

Please sign in to comment.