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

Feature/obi 483 refundable ammounts #15

Open
wants to merge 7 commits into
base: obi/develop
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules/
coverage/
*.snap.ts
*.snap.ts
typings/
2 changes: 0 additions & 2 deletions graphql/types/ReturnSettings.graphql
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
input ReturnSettingsFilters {
id: String
sellerName: String

}

type ReturnSettingsList {
list: [ReturnSettingsResponse!]!
paging: Pagination!
}


type ReturnSettingsResponse {
id: ID!
sellerId: String
Expand Down
2 changes: 1 addition & 1 deletion graphql/types/SellerSetting.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type SellerSettingResponseList {
sellers: [SellerSetting]
}

input SellerSettingInput {
input SellerSettingInput {
id: String
sellerId: String!
parentAccount: String
Expand Down
12 changes: 4 additions & 8 deletions masterdata/goodwill/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
"type": "string",
"description": "Unique identifier for the seller."
},
"status": { "$ref": "#/$defs/status" },
"status": {
"$ref": "#/$defs/status"
},
"creditAmount": {
"type": "number",
"description": "Amount to be credited.",
Expand Down Expand Up @@ -40,11 +42,5 @@
"default": "new"
}
},
"required": [
"orderId",
"creditAmount",
"reason",
"sellerId",
"refundPaymentData"
]
"required": ["creditAmount", "reason", "sellerId", "refundPaymentData"]
}
3 changes: 3 additions & 0 deletions masterdata/goodwill/security.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"allowGetAll": true
}
47 changes: 47 additions & 0 deletions masterdata/orderRefundsSummary/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"properties": {
"orderValue": {
"type": "integer"
},
"refundable": {
"type": "object",
"properties": {
"items": {
"type": "integer"
},
"shipping": {
"type": "integer"
}
},
"required": ["items", "shipping"]
},
"refunds": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"type": {
"type": "string",
"enum": ["goodwill", "prerefund", "refund", "invoice"]
},
"status": {
"type": "string",
"enum": ["pending", "accepted", "denied"]
},
"value": {
"type": "integer"
}
},
"required": ["id", "type", "status", "value"]
}
}
},
"required": ["orderValue", "refundable", "refunds"],
"v-cache": false,
"v-default-fields": ["id", "createdIn"],
"v-indexed": ["id"],
"v-immediate-indexing": true
}
3 changes: 3 additions & 0 deletions masterdata/orderRefundsSummary/security.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"allowGetAll": true
}
17 changes: 12 additions & 5 deletions node/clients/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,27 @@ import { IOClients, Sphinx } from '@vtex/api'
import { vbaseFor, masterDataFor } from '@vtex/clients'

import type { ReturnAppSettings } from '../../typings/ReturnAppSettings'
import type { ReturnRequest } from '../../typings/ReturnRequest'
import type { SellerSetting } from '../../typings/SellerSetting'
import { SellerSetting } from '../../typings/SellerSetting'
import { Catalog } from './catalog'
import { OMSCustom as OMS } from './oms'
import { GiftCard } from './giftCard'
import { MailClient } from './mail'
import Checkout from './checkout'
import { VtexId } from './vtexId'
import { CatalogGQL } from './catalogGQL'
import ReturnRequestClient from './returnRequest'
import OrderRefundsSummaryClient from './orderRefundsSummary'
import { ProfileClient } from './profile'
import { Marketplace } from './marketplace'
import Scheduler from './scheduler'

const SellerSetting = masterDataFor<SellerSetting>('sellerSetting')

const ReturnAppSettingsClient = vbaseFor<string, ReturnAppSettings>(
'appSettings'
)

const ReturnRequestClient = masterDataFor<ReturnRequest | any>('returnRequest')
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const GoodwillClient = masterDataFor<Goodwill | any>('goodwill')
const SellerSettingClient = masterDataFor<SellerSetting>('sellerSetting')
const OrderRefundDetails =
Expand All @@ -42,8 +45,12 @@ export class Clients extends IOClients {
return this.getOrSet('catalogGQL', CatalogGQL)
}

public get returnRequest() {
return this.getOrSet('returnRequest', ReturnRequestClient)
public get returnRequestClient() {
return this.getOrSet('ReturnRequestClient', ReturnRequestClient)
}

public get orderRefundsSummaryClient() {
return this.getOrSet('OrderRefundsSummaryClient', OrderRefundsSummaryClient)
}

public get goodwill() {
Expand Down
2 changes: 1 addition & 1 deletion node/clients/mail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class MailClient extends JanusClient {
return this.http.post(TEMPLATE_RENDER_PATH, template, {
headers: {
...this.options?.headers,
VtexIdClientAutCookie: this.context.adminUserAuthToken || '',
VtexIdClientAutCookie: this.context.adminUserAuthToken ?? '',
},
metric: 'mail-post-template',
})
Expand Down
5 changes: 3 additions & 2 deletions node/clients/oms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ export class OMSCustom extends OMS {
invoice,
{
headers: {
VtexIdClientAutCookie: this.context.adminUserAuthToken ?? this.context.authToken ?? '',
'X-Vtex-Use-Https': 'true',
VtexIdClientAutCookie:
this.context.adminUserAuthToken ?? this.context.authToken ?? '',
'X-Vtex-Use-Https': 'true',
},
metric: 'oms-create-invoice',
}
Expand Down
9 changes: 9 additions & 0 deletions node/clients/orderRefundsSummary.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { masterDataFor } from '@vtex/clients'

import type { OrderRefundsSummary } from '../../typings/OrderRefundsSummary'

const OrderRefundsSummaryClient = masterDataFor<OrderRefundsSummary>(
'orderRefundsSummary'
)

export default OrderRefundsSummaryClient
7 changes: 7 additions & 0 deletions node/clients/returnRequest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { masterDataFor } from '@vtex/clients'

import type { ReturnRequest } from '../../typings/ReturnRequest'

const ReturnRequestClient = masterDataFor<ReturnRequest>('returnRequest')

export default ReturnRequestClient
2 changes: 1 addition & 1 deletion node/clients/vtexId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class VtexId extends JanusClient {
const response = await this.http.get(`/api/vlm/account?an=${account}`, {
metric: 'vtexid-get-account',
headers: {
VtexIdClientAutCookie: token || '',
VtexIdClientAutCookie: token ?? '',
},
})

Expand Down
7 changes: 6 additions & 1 deletion node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ const {
sellerValidation,
getOrdersList,
createGiftcard,
getOrderRefundsSummary,
createPrerefund,
invoice,
} = middlewares

const TIMEOUT_MS = 5000
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const catalogMemoryCache = new LRUCache<string, any>({ max: 5000 })

const clients: ClientsConfig<Clients> = {
Expand Down Expand Up @@ -208,7 +210,10 @@ export default new Service<Clients, State, ParamsContext>({
POST: [ping],
}),
invoice: method({
POST: [auth, invoice],
POST: [invoice],
}),
orderSummary: method({
POST: [getOrderRefundsSummary],
}),
},
graphql: {
Expand Down
2 changes: 1 addition & 1 deletion node/middlewares/errorHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export async function errorHandler(ctx: Context, next: () => Promise<void>) {
error,
})

ctx.status = error.status || error.response?.status || 500
ctx.status = error.status ?? error.response?.status ?? 500
ctx.body = { error: error.message }
ctx.app.emit('error', error, ctx)
}
Expand Down
44 changes: 44 additions & 0 deletions node/middlewares/getOrderRefundsSummary.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import returnOrderRefundsSumaryService from '../services/returnOrderRefundsSummaryService'

async function getOrderRefundsSummary(ctx: Context) {
try {
const {
vtex: {
logger,
route: { params },
},
clients: {
returnRequestClient,
oms,
goodwill,
orderRefundsSummaryClient,
},
} = ctx

const orderId = params.orderId as string

const response = await returnOrderRefundsSumaryService({
clients: {
goodwillClient: goodwill,
logger,
omsClient: oms,
orderRefundsSummaryClient,
returnRequestClient,
},
orderId,
})

if (response === null) throw new Error('Internal error')

ctx.body = {
data: response,
}
ctx.status = 200
} catch (e) {
ctx.status = 500
}

ctx.set('Cache-Control', 'no-cache')
}

export default getOrderRefundsSummary
4 changes: 3 additions & 1 deletion node/middlewares/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { sellerValidation } from './sellerValidation'
import { getOrdersList } from './getOrdersList'
import { createGiftcard } from './giftcard'
import { exportRequests } from './exportRequests'
import getOrderRefundsSummary from './getOrderRefundsSummary'
import { createPrerefund } from './createPrerefund'
import { invoice } from './invoice'

Expand All @@ -30,6 +31,7 @@ export const middlewares = {
getOrdersList,
createGiftcard,
exportRequests,
getOrderRefundsSummary,
createPrerefund,
invoice
invoice,
}
7 changes: 4 additions & 3 deletions node/middlewares/invoice.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { json } from "co-body"
import { createInvoice } from "../services/createInvoice"
import { json } from 'co-body'

import { createInvoice } from '../services/createInvoice'

export async function invoice(ctx: Context): Promise<any> {
const {
Expand All @@ -10,8 +11,8 @@ export async function invoice(ctx: Context): Promise<any> {
},
},
} = ctx

const body = await json(req)

ctx.body = await createInvoice(ctx, orderId, body)

}
10 changes: 5 additions & 5 deletions node/middlewares/sellerSetting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
import { SETTINGS_PATH } from '../utils/constants'

export async function saveSellerSetting(ctx: Context) {
const { body }: any = ctx || {}
const { body }: any = ctx ?? {}

ctx.set('Cache-Control', 'no-cache')

Expand All @@ -25,8 +25,8 @@ export async function saveSellerSetting(ctx: Context) {

ctx.status = 200
} catch (error) {
ctx.body = error?.response?.data || error.response?.statusText || error
ctx.status = error.response?.status || 400
ctx.body = error?.response?.data ?? error.response?.statusText ?? error
ctx.status = error.response?.status ?? 400
}
}

Expand Down Expand Up @@ -73,7 +73,7 @@ export async function returnSellerSetting(ctx: Context) {
throw new UserInputError('sellerId is required')
}
} catch (error) {
ctx.body = error?.response?.data || error.response?.statusText || error
ctx.status = error.response?.status || 400
ctx.body = error?.response?.data ?? error.response?.statusText ?? error
ctx.status = error.response?.status ?? 400
}
}
7 changes: 3 additions & 4 deletions node/middlewares/sellerValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@ export async function sellerValidation(
let seller = ''
const sellerNameSettintgs = settings?.sellerId

seller = sellerNameSettintgs || sellerName
seller = sellerNameSettintgs ?? sellerName
const { sellerId } = params as { sellerId: string }
if (
(_sellerName || _sellerId || seller || sellerId || body.sellerId)
) {

if (_sellerName || _sellerId || seller || sellerId || body.sellerId) {
const accountName = String(
_sellerName || _sellerId || seller || sellerId || body.sellerId
)
Expand Down
4 changes: 2 additions & 2 deletions node/middlewares/setSchema.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { SCHEMAS } from "../utils/constants"
import { SCHEMAS } from '../utils/constants'

export async function setSchemaVersion(
ctx: Context,
next: () => Promise<any>
): Promise<any> {
ctx.clients.returnRequest.schema = SCHEMAS.DEFAULT
ctx.clients.returnRequestClient.schema = SCHEMAS.DEFAULT
ctx.clients.goodwill.schema = SCHEMAS.DEFAULT
ctx.clients.sellerSetting.schema = SCHEMAS.DEFAULT
ctx.clients.orderRefundDetails.schema = SCHEMAS.DEFAULT
Expand Down
Loading