Skip to content

Commit

Permalink
feat(api): add new repo method to save 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 2991c99 commit 79d7276
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,22 @@ const findLastVersionByTypeAndService = async ({ type, service }) => {
return new LegalDocument(documentVersionDto);
};

export { findLastVersionByTypeAndService };
/**
* Creates a new legal document in the database.
*
* @param {Object} params - The parameters.
* @param {string} params.type - The type of the legal document.
* @param {string} params.service - The service associated with the legal document.
* @param {Date} params.versionAt - The date of the legal document version.
* @returns {Promise<LegalDocument>} The newly created legal document.
*/
const createLegalDocument = async ({ type, service, versionAt }) => {
const knexConnection = DomainTransaction.getConnection();

const [documentVersionDto] = await knexConnection('legal-document-versions')
.insert({ type, service, versionAt })
.returning('*');
return new LegalDocument(documentVersionDto);
};

export { createLegalDocument, findLastVersionByTypeAndService };
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,24 @@ describe('Integration | Legal document | Infrastructure | Repository | legal-doc
expect(lastDocument).to.be.null;
});
});

describe('#createLegalDocument', function () {
it('creates a new legal document in the database', async function () {
// given
const type = TOS;
const service = PIX_ORGA;
const versionAt = new Date('2024-12-01');

// when
const createdDocument = await legalDocumentRepository.createLegalDocument({ type, service, versionAt });

// then
expect(createdDocument).to.be.instanceOf(LegalDocument);
expect(createdDocument).to.deep.include({
type,
service,
versionAt,
});
});
});
});

0 comments on commit 79d7276

Please sign in to comment.