Skip to content

Commit

Permalink
fix(get-lineitem.spec.ts): add support for ownerCustomerId in Custome…
Browse files Browse the repository at this point in the history
…rOrderServiceGetLineItem

fix(get-lineitem.ts): add support for ownerCustomerId in CustomerOrderServiceGetLineItem
fix(get.ts): add support for ownerCustomerId in CustomerOrderServiceGet
fix(list.ts): add support for ownerCustomerId in CustomerOrderServiceList
fix(order.schema.ts): add indexes for ownerCustomerId in OrdreMongooseSchema
  • Loading branch information
jamalsoueidan committed Dec 14, 2023
1 parent 70bd3e2 commit de70e13
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 14 deletions.
13 changes: 12 additions & 1 deletion src/functions/customer/services/order/get-lineitem.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,26 @@ describe("CustomerOrderServiceGetLineItem", () => {

const lineItemId = response.line_items[0].id;

// both the beauty professional and customer can see the order
const ownerCustomerId = response.customer.id;
const customerId = response.line_items[0].properties?.customerId || 0;

const order = await CustomerOrderServiceGetLineItem({
let order = await CustomerOrderServiceGetLineItem({
customerId,
lineItemId,
});

expect(order.line_items.id).toEqual(lineItemId);
expect(order.fulfillments.length).toBe(1);
expect(order.refunds.length).toBe(1);

order = await CustomerOrderServiceGetLineItem({
customerId: ownerCustomerId,
lineItemId,
});

expect(order.line_items.id).toEqual(lineItemId);
expect(order.fulfillments.length).toBe(1);
expect(order.refunds.length).toBe(1);
});
});
18 changes: 16 additions & 2 deletions src/functions/customer/services/order/get-lineitem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ export const CustomerOrderServiceGetLineItem = async ({
$match: {
$and: [
{
"line_items.properties.customerId": customerId,
$or: [
{
"line_items.properties.customerId": customerId,
},
{
"customer.id": customerId,
},
],
},
{
line_items: {
Expand All @@ -31,7 +38,14 @@ export const CustomerOrderServiceGetLineItem = async ({
$match: {
$and: [
{
"line_items.properties.customerId": customerId,
$or: [
{
"line_items.properties.customerId": customerId,
},
{
"customer.id": customerId,
},
],
},
{
"line_items.id": lineItemId,
Expand Down
9 changes: 8 additions & 1 deletion src/functions/customer/services/order/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@ export const CustomerOrderServiceGet = async ({
$match: {
$and: [
{
"customer.id": customerId,
$or: [
{
"line_items.properties.customerId": customerId,
},
{
"customer.id": customerId,
},
],
},
{
id: orderId,
Expand Down
18 changes: 16 additions & 2 deletions src/functions/customer/services/order/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,14 @@ export const CustomerOrderServiceList = async ({
$match: {
$and: [
{
"line_items.properties.customerId": customerId,
$or: [
{
"line_items.properties.customerId": customerId,
},
{
"customer.id": customerId,
},
],
},
{
"line_items.properties.from": {
Expand All @@ -58,7 +65,14 @@ export const CustomerOrderServiceList = async ({
$match: {
$and: [
{
"line_items.properties.customerId": customerId,
$or: [
{
"line_items.properties.customerId": customerId,
},
{
"customer.id": customerId,
},
],
},
{
"line_items.properties.from": {
Expand Down
39 changes: 31 additions & 8 deletions src/functions/order/order.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,10 @@ const LineItemSchema = new Schema(
product_exists: Boolean,
product_id: Number,
properties: {
from: Date,
from: {
type: Date,
index: true,
},
to: Date,
customerId: { type: Number, index: true },
locationId: String,
Expand All @@ -148,13 +151,6 @@ const LineItemSchema = new Schema(
}
);

LineItemSchema.index({ id: 1, "properties.customerId": 1 }, { unique: true });

LineItemSchema.index(
{ "properties.from": 1, "properties.customerId": 1 },
{ unique: false }
);

const FulfillmentSchema = new Schema(
{
id: {
Expand Down Expand Up @@ -343,3 +339,30 @@ export const OrdreMongooseSchema = new Schema<IOrderDocument, IOrderModel>({
shipping_address: AddressSchema,
shipping_lines: [ShippingLineSchema],
});

// orders/get-line-item
OrdreMongooseSchema.index(
{ "customer.id": 1, "line_items.id": 1 },
{ unique: false }
);
OrdreMongooseSchema.index(
{ "line_items.properties.customerId": 1, "line_items.id": 1 },
{ unique: false }
);

// orders/get
OrdreMongooseSchema.index({ "customer.id": 1, id: 1 }, { unique: false });
OrdreMongooseSchema.index(
{ "line_items.properties.customerId": 1, id: 1 },
{ unique: false }
);

// order/list
OrdreMongooseSchema.index(
{ "customer.id": 1, "line_items.properties.from": 1 },
{ unique: false }
);
OrdreMongooseSchema.index(
{ "line_items.properties.customerId": 1, "line_items.properties.from": 1 },
{ unique: false }
);

0 comments on commit de70e13

Please sign in to comment.