-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): add script to save a new legal document version
- Loading branch information
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
api/scripts/legal-documents/add-new-legal-document-version.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import 'dotenv/config'; | ||
|
||
import { usecases } from '../../src/legal-documents/domain/usecases/index.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}`); | ||
|
||
await usecases.createLegalDocument({ type, service, versionAt }); | ||
logger.info(`New legal document for type:${type}, service:${service}, versionAt:${versionAt} added successfully.`); | ||
} | ||
} | ||
|
||
await ScriptRunner.execute(import.meta.url, AddNewLegalDocumentVersion); |