Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pangolin 3186: add quote model #436

Merged
merged 3 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/plenty-jobs-brush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@commercetools-test-data/quote': minor
'@commercetools-test-data/quote-request': patch
'@commercetools-test-data/staged-quote': patch
---

feat(quote model): adds package for `Quote` and `QuoteDraft` models
26 changes: 12 additions & 14 deletions models/quote-request/src/transformers.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import {
StoreKeyReference,
BusinessUnitKeyReference,
StoreKeyReference,
} from '@commercetools/platform-sdk';
import {
Reference,
KeyReference,
TReference,
TReferenceGraphql,
TKeyReferenceGraphql,
} from '@commercetools-test-data/commons';
import { Transformer } from '@commercetools-test-data/core';

Expand Down Expand Up @@ -66,7 +67,7 @@ const transformers = {
const store = KeyReference.random()
.typeId('store')
.key(fields.store?.key)
.buildRest() as unknown as StoreKeyReference;
.buildRest<StoreKeyReference>();

const state = Reference.presets.stateReference
.stateReference()
Expand All @@ -76,7 +77,7 @@ const transformers = {
const businessUnit = KeyReference.random()
.typeId('business-unit')
.key(fields.businessUnit?.key)
.buildRest() as unknown as BusinessUnitKeyReference;
.buildRest<BusinessUnitKeyReference>();

return {
...fields,
Expand Down Expand Up @@ -119,10 +120,9 @@ const transformers = {
.typeId('customer-group')
.buildGraphql();

const storeRef: TReferenceGraphql = Reference.presets.storeReference
.storeReference()
.id(fields.store?.id)
.typeId('store')
const storeRef: TKeyReferenceGraphql = KeyReference.presets
.store()
.key(fields.store?.key)
.buildGraphql();

const stateRef: TReferenceGraphql = Reference.presets.stateReference
Expand All @@ -139,20 +139,18 @@ const transformers = {
.buildGraphql()
: null;

const businessUnitRef: TReferenceGraphql =
Reference.presets.businessUnitReference
.businessUnitReference()
.id(fields.businessUnit?.id)
.typeId('business-unit')
.buildGraphql();
const businessUnitRef: TKeyReferenceGraphql = KeyReference.presets
.businessUnit()
.key(fields.businessUnit?.key)
.buildGraphql();

return {
customerRef,
customerGroupRef: fields.customerGroup ? customerGroupRef : undefined,
storeRef: fields.store ? storeRef : undefined,
stateRef: fields.state ? stateRef : undefined,
cartRef: fields.cart ? cartRef : undefined,
businessUnitRef,
businessUnitRef: fields.businessUnit ? businessUnitRef : undefined,
__typename: 'QuoteRequest',
};
},
Expand Down
10 changes: 6 additions & 4 deletions models/quote-request/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import type {
BusinessUnit,
CartReference,
Customer,
CustomerGroup,
State,
Store,
QuoteRequest,
QuoteRequestDraft,
} from '@commercetools/platform-sdk';
import { TReferenceGraphql } from '@commercetools-test-data/commons';
import {
TReferenceGraphql,
TKeyReferenceGraphql,
} from '@commercetools-test-data/commons';
import type { TBuilder } from '@commercetools-test-data/core';

// Default
Expand All @@ -30,10 +32,10 @@ export type TQuoteRequestDraft = QuoteRequestDraft;
export type TQuoteRequestGraphql = TQuoteRequest & {
customerRef: TReferenceGraphql | null;
customerGroupRef: TReferenceGraphql | null;
storeRef: TReferenceGraphql | null;
storeRef: TKeyReferenceGraphql | null;
stateRef: TReferenceGraphql | null;
cartRef: TReferenceGraphql | null;
businessUnitRef: TReferenceGraphql | null;
businessUnitRef: TKeyReferenceGraphql | null;
__typename: 'QuoteRequest';
};
export type TQuoteRequestDraftGraphql = TQuoteRequestDraft;
Expand Down
21 changes: 21 additions & 0 deletions models/quote/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) commercetools GmbH

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
25 changes: 25 additions & 0 deletions models/quote/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# @commercetools-test-data/quote

This package provides the data model for the commercetools platform `Quote` type

https://docs.commercetools.com/api/projects/quotes

# Install

```bash
$ pnpm add -D @commercetools-test-data/quote
```

# Usage

```ts
import {
Quote,
QuoteDraft,
type TQuote,
type TQuoteDraft,
} from '@commercetools-test-data/quote';

const quote = Quote.random().build<TQuote>();
const quoteDraft = QuoteDraft.random().build<TQuoteDraft>();
```
35 changes: 35 additions & 0 deletions models/quote/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "@commercetools-test-data/quote",
"version": "6.5.0",
"description": "Data model for commercetools API Quote",
"bugs": "https://github.com/commercetools/test-data/issues",
"repository": {
"type": "git",
"url": "https://github.com/commercetools/test-data.git",
"directory": "models/quote"
},
"keywords": ["javascript", "typescript", "test-data"],
"license": "MIT",
"publishConfig": {
"access": "public"
},
"main": "dist/commercetools-test-data-quote.cjs.js",
"module": "dist/commercetools-test-data-quote.esm.js",
"files": ["dist", "package.json", "LICENSE", "README.md"],
"dependencies": {
"@babel/runtime": "^7.17.9",
"@babel/runtime-corejs3": "^7.17.9",
"@commercetools-test-data/business-unit": "6.5.0",
"@commercetools-test-data/cart": "6.5.0",
"@commercetools-test-data/commons": "6.5.0",
"@commercetools-test-data/core": "6.5.0",
"@commercetools-test-data/customer": "6.5.0",
"@commercetools-test-data/customer-group": "6.5.0",
"@commercetools-test-data/quote-request": "6.5.0",
"@commercetools-test-data/staged-quote": "^6.5.0",
"@commercetools-test-data/store": "6.5.0",
"@commercetools-test-data/utils": "6.5.0",
"@commercetools/platform-sdk": "^7.0.0",
"@faker-js/faker": "^8.3.1"
}
}
Loading
Loading