Skip to content

Commit

Permalink
[Seller Quotes] feat: quote new fields and create children quote for … (
Browse files Browse the repository at this point in the history
#68)

* [Seller Quotes] feat: quote new fields and create children quote for marketplace when splitted if necessary (#66)

* [Seller Quotes] feat: get seller quotes paginated api (#61)

* feat: add new markeplace splitting quotes on graphql

* feat: checking new field quotesManagedBy when value is SELLER

* docs: update CHANGELOG

* feat: add configuration for quote creation

* feat: add adjustment for quote seller

* chore: fix prettier errors

* fix: returning ids separated by commas when multiple quotes

* fix: check config and default settings with marketplace option

* feat: new fields for quotes managed by seller

* feat: new fields to save parent quote; change getQuotes query to filter only parent quotes

* feat: create client to notify seller quote

* feat: add changelog

* feat: verify and notify seller quote

* chore: removes console.log from SellerQuotesClient

* docs: update CHANGELOG and prettier fix on markdown

* fix: right splitting of seller quotes

* feat: refactor on creating seller quote map; avoid double check of seller

* refactor: seller quotes client constants

* feat: send creationDate on notify seller quote

* feat: provides a route for seller get a quote by id at marketplace

* docs: update CHANGELOG

* refactor: separating get seller quote into smaller functions

* refactor: function to get org anc cost center names

* refactor: create service class for seller quotes

* fix: removing approvedBySeller field from quote entity

* refactor: renaming seller quotes service to controller

* feat: get seller quotes paginated

* feat: use seller quote controller

* docs: add changelog

* chore: fix misspell

* fix: use array destructuring

* fix: sorting get seller quotes for right pagination

* feat: supporting search and status filters on get seller quotes

* feat: using search filter on quote creator email

* fix: right dependencies

* fix: remove p-limit from root package.json

* feat: suport for custom sort and where on ger seller quotes paginated

* [Seller Quotes] Add new markeplace splitting quotes on graphql (#57)

* feat: add new markeplace splitting quotes on graphql

* docs: update CHANGELOG

* chore: fix prettier errors

* fix: check config and default settings with marketplace option

* docs: update CHANGELOG and prettier fix on markdown

---------

Co-authored-by: Bruna Santos <[email protected]>
Co-authored-by: Tiago de Andrade Freire <[email protected]>
Co-authored-by: Tiago de Andrade Freire <[email protected]>

---------

Co-authored-by: Bruna Santos <[email protected]>
Co-authored-by: Tiago de Andrade Freire <[email protected]>
Co-authored-by: Tiago de Andrade Freire <[email protected]>
Co-authored-by: BrunaCubos <[email protected]>

* [Seller Quotes] feat: endpoint to save a seller quote (#62)

* feat: add new markeplace splitting quotes on graphql

* feat: checking new field quotesManagedBy when value is SELLER

* docs: update CHANGELOG

* feat: add configuration for quote creation

* feat: add adjustment for quote seller

* chore: fix prettier errors

* fix: returning ids separated by commas when multiple quotes

* fix: check config and default settings with marketplace option

* feat: new fields for quotes managed by seller

* feat: new fields to save parent quote; change getQuotes query to filter only parent quotes

* feat: create client to notify seller quote

* feat: add changelog

* feat: verify and notify seller quote

* chore: removes console.log from SellerQuotesClient

* docs: update CHANGELOG and prettier fix on markdown

* fix: right splitting of seller quotes

* feat: refactor on creating seller quote map; avoid double check of seller

* refactor: seller quotes client constants

* feat: send creationDate on notify seller quote

* feat: provides a route for seller get a quote by id at marketplace

* docs: update CHANGELOG

* refactor: separating get seller quote into smaller functions

* refactor: function to get org anc cost center names

* refactor: create service class for seller quotes

* fix: removing approvedBySeller field from quote entity

* refactor: renaming seller quotes service to controller

* feat: provides a route for seller save a quote at marketplace

* feat: get seller quotes paginated

* feat: use seller quote controller

* docs: add changelog

* chore: fix misspell

* fix: use array destructuring

* fix: sorting get seller quotes for right pagination

* feat: supporting search and status filters on get seller quotes

* feat: using search filter on quote creator email

* fix: right dependencies

* fix: remove p-limit from root package.json

* feat: suport for custom sort and where on ger seller quotes paginated

* [Seller Quotes] Add new markeplace splitting quotes on graphql (#57)

* feat: add new markeplace splitting quotes on graphql

* docs: update CHANGELOG

* chore: fix prettier errors

* fix: check config and default settings with marketplace option

* docs: update CHANGELOG and prettier fix on markdown

---------

Co-authored-by: Bruna Santos <[email protected]>
Co-authored-by: Tiago de Andrade Freire <[email protected]>
Co-authored-by: Tiago de Andrade Freire <[email protected]>

---------

Co-authored-by: Bruna Santos <[email protected]>
Co-authored-by: Guido Bernal <[email protected]>
Co-authored-by: BrunaCubos <[email protected]>

* [Seller Quotes] Add query for quote parent id (#63)

* feat: add new markeplace splitting quotes on graphql

* feat: checking new field quotesManagedBy when value is SELLER

* docs: update CHANGELOG

* feat: add configuration for quote creation

* feat: add adjustment for quote seller

* chore: fix prettier errors

* fix: returning ids separated by commas when multiple quotes

* fix: check config and default settings with marketplace option

* feat: new fields for quotes managed by seller

* feat: new fields to save parent quote; change getQuotes query to filter only parent quotes

* feat: create client to notify seller quote

* feat: add changelog

* feat: verify and notify seller quote

* chore: removes console.log from SellerQuotesClient

* docs: update CHANGELOG and prettier fix on markdown

* fix: right splitting of seller quotes

* feat: refactor on creating seller quote map; avoid double check of seller

* refactor: seller quotes client constants

* feat: send creationDate on notify seller quote

* feat: provides a route for seller get a quote by id at marketplace

* docs: update CHANGELOG

* refactor: separating get seller quote into smaller functions

* refactor: function to get org anc cost center names

* refactor: create service class for seller quotes

* fix: removing approvedBySeller field from quote entity

* refactor: renaming seller quotes service to controller

* feat: provides a route for seller save a quote at marketplace

* feat: get seller quotes paginated

* feat: use seller quote controller

* docs: add changelog

* chore: fix misspell

* fix: use array destructuring

* fix: sorting get seller quotes for right pagination

* feat: supporting search and status filters on get seller quotes

* feat: using search filter on quote creator email

* feat: add split quote query

* fix: right dependencies

* fix: remove p-limit from root package.json

* feat: suport for custom sort and where on ger seller quotes paginated

* [Seller Quotes] Add new markeplace splitting quotes on graphql (#57)

* feat: add new markeplace splitting quotes on graphql

* docs: update CHANGELOG

* chore: fix prettier errors

* fix: check config and default settings with marketplace option

* docs: update CHANGELOG and prettier fix on markdown

---------

Co-authored-by: Bruna Santos <[email protected]>
Co-authored-by: Tiago de Andrade Freire <[email protected]>
Co-authored-by: Tiago de Andrade Freire <[email protected]>

---------

Co-authored-by: Bruna Santos <[email protected]>
Co-authored-by: Tiago de Andrade Freire <[email protected]>
Co-authored-by: Tiago de Andrade Freire <[email protected]>
Co-authored-by: Guido Bernal <[email protected]>

* Fix code scanning alert no. 4: Incomplete string escaping or encoding

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>

* feat: new quote fields creatorName, sellerName and childrenQuantity

* docs: update CHANGELOG

* fix: update lastUpdate on handle parent quote status and subtotal

* feat: creating parent quote only on multiple quotes; handling creatorName

* feat: handling use, decline and place order of children quotes

* fix: creatorName masterdata type

* fix: seller quote only receive updates from your orders

* feat: add query checkSellerQuotes; remove storeName setting; do not receive seller name

* fix: remove declining children; seller quotes should be created with pending status

---------

Co-authored-by: guidobernal-cubos <[email protected]>
Co-authored-by: Bruna Santos <[email protected]>
Co-authored-by: BrunaCubos <[email protected]>
Co-authored-by: Matheus-Aguilar <[email protected]>
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>

* fix: fixing code smells

* fix: fixing lint issues

* fix: remove more code smells

* fix: solve more sonarcloud issues

---------

Co-authored-by: Tiago Freire <[email protected]>
Co-authored-by: guidobernal-cubos <[email protected]>
Co-authored-by: Bruna Santos <[email protected]>
Co-authored-by: BrunaCubos <[email protected]>
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
  • Loading branch information
6 people authored Jan 23, 2025
1 parent 849665d commit 00bfb65
Show file tree
Hide file tree
Showing 17 changed files with 440 additions and 155 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Add fields creatorName, sellerName and childrenQuantity on quote entity
- Saving masterdata schema hash in settings to update when it changes
- Create a new quote to marketplace responsibility for remaining items when splitting a quote
- Create a new query to check sellers quotes on frontend

### Changed

- Handle parent quote status and subtotal when updating splitted quotes
- Get all children quotes ordered by lastUpdate DESC once on getChildrenQuotes

## [2.8.0] - 2025-01-13

### Added
Expand Down
8 changes: 8 additions & 0 deletions graphql/quote.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type Quote {
id: String
referenceName: String
creatorEmail: String
creatorName: String
creatorRole: String
creationDate: String
expirationDate: String
Expand All @@ -60,8 +61,10 @@ type Quote {
viewedByCustomer: Boolean
salesChannel: String
seller: String
sellerName: String
parentQuote: String
hasChildren: Boolean
childrenQuantity: Int
}

type QuoteUpdate {
Expand All @@ -85,3 +88,8 @@ type QuoteItem {
sellingPrice: Float
seller: String
}

type Seller {
id: String
name: String
}
10 changes: 7 additions & 3 deletions graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,15 @@ type Query {
@cacheControl(scope: PRIVATE, maxAge: SHORT)
getChildrenQuotes(
id: String
page: Int = 1
pageSize: Int = 25
sortOrder: String = "DESC"
sortedBy: String = "lastUpdate"
): Quotes
): [Quote]
@auditAccess
@withPermissions
@withSession
@withSegment
@cacheControl(scope: PRIVATE, maxAge: SHORT)
checkSellerQuotes(sellers: [String!]!): [Seller!]!
@auditAccess
@withPermissions
@withSession
Expand Down
4 changes: 1 addition & 3 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
"vtex.b2b-organizations-graphql": "0.x",
"vtex.orders-broadcast": "0.x"
},
"registries": [
"smartcheckout"
],
"registries": ["smartcheckout"],
"policies": [
{
"name": "vbase-read-write"
Expand Down
18 changes: 18 additions & 0 deletions node/clients/SellerClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { IOContext, InstanceOptions } from '@vtex/api'
import { JanusClient } from '@vtex/api'

export default class SellerClient extends JanusClient {
constructor(context: IOContext, options?: InstanceOptions) {
super(context, {
...options,
headers: {
...options?.headers,
VtexIdclientAutcookie: context.authToken,
},
})
}

public async getSeller(sellerId: string) {
return this.http.get<Seller>(`/api/seller-register/pvt/sellers/${sellerId}`)
}
}
5 changes: 5 additions & 0 deletions node/clients/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import Organizations from './organizations'
import StorefrontPermissions from './storefrontPermissions'
import VtexId from './vtexId'
import SellerQuotesClient from './SellerQuotesClient'
import SellerClient from './SellerClient'

export const getTokenToHeader = (ctx: IOContext) => {
// provide authToken (app token) as an admin token as this is a call
Expand Down Expand Up @@ -91,4 +92,8 @@ export class Clients extends IOClients {
public get sellerQuotes() {
return this.getOrSet('sellerQuotes', SellerQuotesClient)
}

public get seller() {
return this.getOrSet('seller', SellerClient)
}
}
20 changes: 20 additions & 0 deletions node/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const QUOTE_FIELDS = [
'id',
'referenceName',
'creatorEmail',
'creatorName',
'creatorRole',
'creationDate',
'expirationDate',
Expand All @@ -23,8 +24,10 @@ export const QUOTE_FIELDS = [
'viewedByCustomer',
'salesChannel',
'seller',
'sellerName',
'parentQuote',
'hasChildren',
'childrenQuantity',
]

export const routes = {
Expand Down Expand Up @@ -87,6 +90,10 @@ export const schema = {
title: 'Creator Email',
type: 'string',
},
creatorName: {
title: 'Creator Name',
type: ['null', 'string'],
},
creatorRole: {
title: 'Creator Role',
type: 'string',
Expand Down Expand Up @@ -141,6 +148,10 @@ export const schema = {
title: 'Seller',
type: ['null', 'string'],
},
sellerName: {
title: 'Seller Name',
type: ['null', 'string'],
},
parentQuote: {
title: 'Parent quote',
type: ['null', 'string'],
Expand All @@ -149,24 +160,32 @@ export const schema = {
title: 'Has children',
type: ['null', 'boolean'],
},
childrenQuantity: {
title: 'Children Quantity',
type: ['null', 'number'],
},
},
'v-cache': false,
'v-default-fields': [
'referenceName',
'creatorEmail',
'creatorName',
'creationDate',
'expirationDate',
'lastUpdate',
'items',
'subtotal',
'status',
'seller',
'sellerName',
'parentQuote',
'hasChildren',
'childrenQuantity',
],
'v-immediate-indexing': true,
'v-indexed': [
'creatorEmail',
'creatorName',
'creationDate',
'expirationDate',
'lastUpdate',
Expand All @@ -176,6 +195,7 @@ export const schema = {
'costCenter',
'salesChannel',
'seller',
'sellerName',
'parentQuote',
'hasChildren',
],
Expand Down
130 changes: 80 additions & 50 deletions node/middlewares/order.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { QUOTE_DATA_ENTITY, QUOTE_FIELDS, SCHEMA_VERSION } from '../constants'
import SellerQuotesController from '../resolvers/utils/sellerQuotesController'
import { isEmail, NO_REPLY_EMAIL } from '../utils'
import message from '../utils/message'

Expand Down Expand Up @@ -47,58 +48,22 @@ export async function orderHandler(
id: quoteId,
})) as Quote

const quote = {
...item,
status: 'placed',
updateHistory: [
...item.updateHistory,
{
date: new Date().toISOString(),
email: NO_REPLY_EMAIL,
note: `Order ID: ${body.orderId}`,
role: 'order-notification-system',
status: 'placed',
},
],
const quotes: Quote[] = []

quotes.push(item)

if (item.hasChildren) {
const sellerQuotesController = new SellerQuotesController(ctx)
const childrenQuotes = await sellerQuotesController.getAllChildrenQuotes(
quoteId
)

quotes.push(...childrenQuotes)
}

await masterdata
.updateEntireDocument({
dataEntity: QUOTE_DATA_ENTITY,
fields: quote,
id: quoteId,
schema: SCHEMA_VERSION,
})
.then((res: any) => res)

const users = quote.updateHistory.map((anUpdate) => anUpdate.email)

const uniqueUsers = [
...new Set(
users.filter((userEmail: string) => isEmail.test(userEmail))
),
]

message(ctx)
.quoteUpdated({
costCenter: quote.costCenter,
id: quoteId,
lastUpdate: {
email: 'order-notification-system',
note: `Order ID: ${body.orderId}`,
status: 'PLACED',
},
name: quote.referenceName,
orderId: body.orderId,
organization: quote.organization,
templateName: 'quote-order-placed',
users: uniqueUsers,
})
.then(() => {
logger.info({
message: `[Quote placed] E-mail sent ${uniqueUsers.join(', ')}`,
})
})
await Promise.all(
quotes.map((quote) => processQuote(ctx, order, quote))
)
}
}
} catch (error) {
Expand All @@ -112,3 +77,68 @@ export async function orderHandler(

return next()
}

async function processQuote(
ctx: EventBroadcastContext,
order: Order,
quote: Quote
) {
const { orderId } = order

const mustAddUpdateHistory =
!quote.seller ||
(quote.seller && order.items.some((item) => item.seller === quote.seller))

if (mustAddUpdateHistory) {
quote.updateHistory.push({
date: new Date().toISOString(),
email: NO_REPLY_EMAIL,
note: `Order ID: ${orderId}`,
role: 'order-notification-system',
status: 'placed',
})
}

const quoteUpdated = {
...quote,
status: 'placed',
updateHistory: quote.updateHistory,
}

await ctx.clients.masterdata.updateEntireDocument({
dataEntity: QUOTE_DATA_ENTITY,
fields: quoteUpdated,
id: quote.id,
schema: SCHEMA_VERSION,
})

// just users from single or children quotes need to be notified
if (quote.hasChildren) return

const users = quoteUpdated.updateHistory.map((anUpdate) => anUpdate.email)

const uniqueUsers = [
...new Set(users.filter((userEmail: string) => isEmail.test(userEmail))),
]

message(ctx)
.quoteUpdated({
costCenter: quoteUpdated.costCenter,
id: quote.id,
lastUpdate: {
email: 'order-notification-system',
note: `Order ID: ${orderId}`,
status: 'PLACED',
},
name: quoteUpdated.referenceName,
orderId,
organization: quoteUpdated.organization,
templateName: 'quote-order-placed',
users: uniqueUsers,
})
.then(() => {
ctx.vtex.logger.info({
message: `[Quote placed] E-mail sent ${uniqueUsers.join(', ')}`,
})
})
}
4 changes: 2 additions & 2 deletions node/resolvers/fieldResolvers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const organizationName = async (
{ organization }: { organization: string },
_: any,
ctx: Context
ctx: Context | EventBroadcastContext
) => {
const {
clients: { organizations },
Expand All @@ -25,7 +25,7 @@ export const organizationName = async (
export const costCenterName = async (
{ costCenter }: { costCenter: string },
_: any,
ctx: Context
ctx: Context | EventBroadcastContext
) => {
const {
clients: { organizations },
Expand Down
Loading

0 comments on commit 00bfb65

Please sign in to comment.