From fe66a8ecbe4e195cfc7dc6f8f090573d04a123be Mon Sep 17 00:00:00 2001 From: Bryson Armstrong Date: Fri, 6 Dec 2024 12:19:01 -0700 Subject: [PATCH] lint --- server/src/routes/update-inventory/root.ts | 17 ++++++++--------- server/src/shopify/inventory.ts | 13 ++++--------- server/src/shopify/product.ts | 17 ++++++++++------- 3 files changed, 22 insertions(+), 25 deletions(-) diff --git a/server/src/routes/update-inventory/root.ts b/server/src/routes/update-inventory/root.ts index 9b775c0..9bb66be 100644 --- a/server/src/routes/update-inventory/root.ts +++ b/server/src/routes/update-inventory/root.ts @@ -12,8 +12,7 @@ import { // maybe use a generic argument for FastifyPluginAsync if we use options with fastify instance const updateInventory: FastifyPluginAsyncTypebox = async (fastifyApp, { shopifyClient }): Promise => { const fastify = fastifyApp.withTypeProvider() - - const fastifyInstance = fastify.post('/', { + fastify.post('/', { schema: { body: UpdateInventoryRequestSchema, response: { @@ -25,24 +24,24 @@ const updateInventory: FastifyPluginAsyncTypebox = async (fastify }, async (request, reply) => { let inventoryPairs: Array<{ inventoryItemId: string, locationId: string }> | null - if (request.body.variantId) { + if (request.body.variantId != null) { inventoryPairs = await getVariantInventoryLocation(shopifyClient, request.body.variantId) - if (inventoryPairs == null) { + if (inventoryPairs === null) { throw new NotFoundError('Product variant not found') } - } else if (request.body.productId) { + } else if (request.body.productId != null) { inventoryPairs = await getProductInventoryLocation(shopifyClient, request.body.productId) - if (inventoryPairs == null) { + if (inventoryPairs === null) { throw new NotFoundError('Product not found') } } else { throw new InvalidRequestError('Must specify either productId or variantId') } - if (request.body.locationId) { + if (request.body.locationId != null) { inventoryPairs = inventoryPairs.filter(p => p.locationId === request.body.locationId) } - if (inventoryPairs.length == 0) { + if (inventoryPairs.length === 0) { throw new NotFoundError('Inventory Item not found') } if (inventoryPairs.length > 1) { @@ -52,7 +51,7 @@ const updateInventory: FastifyPluginAsyncTypebox = async (fastify const response = await updateAvailableInventory(shopifyClient, inventoryPairs[0].inventoryItemId, inventoryPairs[0].locationId, request.body.quantity) - reply.status(200).send(response) + await reply.status(200).send(response) }) } diff --git a/server/src/shopify/inventory.ts b/server/src/shopify/inventory.ts index 89ee428..e8af1d4 100644 --- a/server/src/shopify/inventory.ts +++ b/server/src/shopify/inventory.ts @@ -1,13 +1,5 @@ import { ShopifyGraphQLClient } from './shopify-client' -import { logger } from '../util/logger' -import { - ProductSchema, - Product, - PageInfo, - PageInfoSchema, - UpdateInventoryResponse, - UpdateInventoryResponseSchema -} from 'shared' +import { UpdateInventoryResponse, UpdateInventoryResponseSchema } from 'shared' import { isValid } from '../util/validate' const MAX_VARIANTS_COUNT = 10 @@ -93,6 +85,7 @@ export async function getVariantInventoryLocation ( }) as { data: Record, errors: unknown } if (errors != null) { + // eslint-disable-next-line @typescript-eslint/no-throw-literal throw errors } @@ -122,6 +115,7 @@ export async function getProductInventoryLocation ( }) as { data: Record, errors: unknown } if (errors != null) { + // eslint-disable-next-line @typescript-eslint/no-throw-literal throw errors } @@ -165,6 +159,7 @@ export async function updateAvailableInventory ( }) as { data: Record, errors: unknown } if (errors != null) { + // eslint-disable-next-line @typescript-eslint/no-throw-literal throw errors } const response: any = data.inventorySetQuantities diff --git a/server/src/shopify/product.ts b/server/src/shopify/product.ts index 88f0861..4bca506 100644 --- a/server/src/shopify/product.ts +++ b/server/src/shopify/product.ts @@ -90,20 +90,23 @@ const getProductsQuery = /* GraphQL */ ` ` function parseProduct (product: any): Product { - product.totalAvailableInventory = 0 - product.totalCommittedInventory = 0 + let totalAvailableInventory: number = 0 + let totalCommittedInventory: number = 0 for (const variant of product.variants.nodes) { for (const inventoryLevel of variant.inventoryItem.inventoryLevels.nodes) { - for (const quantity of inventoryLevel.quantities) { - if (quantity.name == 'available') { - product.totalAvailableInventory += quantity.quantity - } else if (quantity.name == 'committed') { - product.totalCommittedInventory += quantity.quantity + for (const inventoryQuantity of inventoryLevel.quantities) { + const quantity: number = inventoryQuantity.quantity + if (inventoryQuantity.name === 'available') { + totalAvailableInventory += quantity + } else if (inventoryQuantity.name === 'committed') { + totalCommittedInventory += quantity } } } } + product.totalAvailableInventory = totalAvailableInventory + product.totalCommittedInventory = totalCommittedInventory if (!isValid(ProductSchema, product, 'product')) { throw new Error('Error mapping product') }