diff --git a/CHANGELOG.md b/CHANGELOG.md index 9669419..3d4a86a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [0.9.0] - Unreleased +## [0.9.0] - 2021-08-23 ### Added diff --git a/README.md b/README.md index d33d8d8..2850863 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,7 @@ A node implementation to use the Internetmarke web service of Deutsche Post. - [Product List](#product-list) - [Oudated Products](#outdated-products) - [Catalog List](#catalog-list) + - [Match Product for Letter](#match-product-for-letter) ## Installation @@ -474,6 +475,27 @@ const catalogs = await internetmarke.getCatalogList(); const catalog = await internetmarke.getCatalog('Entgeltzone'); ``` +### Match Product for Letter + +Your letter is complete are the only thing left is the voucher. But which one is +neccessary for the letter? The `matchProduct()` method calculates the right one +for you. Depending on your needs and the combination of paper end envelope the +corrept product is retrieved. + +```typescript +const options: MatchProductOptions = { + pages: 1, // the number of pages + paper, // optional, defines the paper format and grammage that is used for the letter, defaults to DIN A4 with 80 g/m² + envelope, // optional, defines the envelope format and grammage that is used for the letter, defaults to DIN Lang with 90 g/m² + domestic, // optional, whether the letter is sent within Germany, defaults to true + priority, // optional, whether the letter should be sent as priority letter, defaults to false + registered, // optional, 'Einschreiben'; whether the letter should as registered letter letter, defaults to false + tracking // optional, whether the letter should trackable, defaults to false +}; + +const product = await internetmarke.matchProduct(options); +``` + [npm-url]: https://npmjs.org/package/internetmarke [npm-svg]: https://img.shields.io/npm/v/internetmarke.svg [npm-downloads-svg]: https://img.shields.io/npm/dm/internetmarke.svg diff --git a/src/prodWs/product.ts b/src/prodWs/product.ts index 9508c0f..c237b1a 100644 --- a/src/prodWs/product.ts +++ b/src/prodWs/product.ts @@ -37,7 +37,7 @@ export interface Product { } export interface MatchProductOptions { - paperCount: number; + pages: number; paper?: | { // defaults to 'A4' @@ -218,8 +218,7 @@ export const matchProduct = (products: Product[], options: MatchProductOptions): } const envelopeDetails = getPaperDetails(matchOptions.envelope!.format, envelopeOptions); - const weight = - paperDetails.weight.value * options.paperCount + (envelopeDetails?.weight.value || 0); + const weight = paperDetails.weight.value * options.pages + (envelopeDetails?.weight.value || 0); const dimensions = envelopeDetails?.dimensions || paperDetails.dimensions; const validProducts = products.filter(product => { diff --git a/test/Internetmarke.spec.ts b/test/Internetmarke.spec.ts index af807b8..436398c 100644 --- a/test/Internetmarke.spec.ts +++ b/test/Internetmarke.spec.ts @@ -74,6 +74,9 @@ describe('Internetmarke', () => { expect(internetmarke.getCatalog('name')).to.eventually.be.rejectedWith(InternetmarkeError), expect(internetmarke.getProductList()).to.eventually.be.rejectedWith(InternetmarkeError), expect(internetmarke.getProduct(0)).to.eventually.be.rejectedWith(InternetmarkeError), + expect(internetmarke.matchProduct({ pages: 1 })).to.eventually.be.rejectedWith( + InternetmarkeError + ), expect(internetmarke.initProductService({} as any)).to.eventually.be.rejected ]); diff --git a/test/prodWs/product/product.spec.ts b/test/prodWs/product/product.spec.ts index 73cc6b6..9531c73 100644 --- a/test/prodWs/product/product.spec.ts +++ b/test/prodWs/product/product.spec.ts @@ -21,28 +21,28 @@ describe('Product', () => { describe('matchProduct', () => { it('should match a product for a single DIN A4 paper in DIN Lang envelope', () => { - const product = matchProduct(productList, { paperCount: 1 })!; + const product = matchProduct(productList, { pages: 1 })!; expect(product).to.exist; expect(product.id).to.equal(1); }); it('should match a product for five DIN A4 papers in DIN Lang envelope', () => { - const product = matchProduct(productList, { paperCount: 5 })!; + const product = matchProduct(productList, { pages: 5 })!; expect(product).to.exist; expect(product.id).to.equal(11); }); it('should match a product for five DIN A5 papers in DIN Lang envelope', () => { - const product = matchProduct(productList, { paperCount: 5, paper: DinPaper.DinA5 })!; + const product = matchProduct(productList, { pages: 5, paper: DinPaper.DinA5 })!; expect(product).to.exist; expect(product.id).to.equal(1); }); it('should match a product for a single DIN A4 paper in DIN C4 envelope', () => { - const product = matchProduct(productList, { paperCount: 5, envelope: DinEnvelope.DinC4 })!; + const product = matchProduct(productList, { pages: 5, envelope: DinEnvelope.DinC4 })!; expect(product).to.exist; expect(product.id).to.equal(21); @@ -50,7 +50,7 @@ describe('Product', () => { xit('should match a product for post cards', () => { const product = matchProduct(productList, { - paperCount: 1, + pages: 1, paper: { format: DinPaper.DinA6, grammage: 150 }, envelope: DinEnvelope.None })!; @@ -60,21 +60,21 @@ describe('Product', () => { }); it('should match a product with priority label', () => { - const product = matchProduct(productList, { paperCount: 1, priority: true })!; + const product = matchProduct(productList, { pages: 1, priority: true })!; expect(product).to.exist; expect(product.id).to.equal(195); }); it('should match a product with registered label', () => { - const product = matchProduct(productList, { paperCount: 1, registered: true })!; + const product = matchProduct(productList, { pages: 1, registered: true })!; expect(product).to.exist; expect(product.id).to.equal(1002); }); it('should match a product for an abroad letter', () => { - const product = matchProduct(productList, { paperCount: 1, domestic: false })!; + const product = matchProduct(productList, { pages: 1, domestic: false })!; expect(product).to.exist; expect(product.id).to.equal(10001);