Skip to content

Commit

Permalink
Merge pull request #161 from jamalsoueidan/remove-location-origin
Browse files Browse the repository at this point in the history
Remove location origin
  • Loading branch information
jamalsoueidan authored Jun 6, 2024
2 parents 792b915 + 0e1fc8c commit 0d3151c
Show file tree
Hide file tree
Showing 35 changed files with 111 additions and 179 deletions.
6 changes: 1 addition & 5 deletions openapi/paths/customer/location/_types/base-location.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@ properties:
type: string
locationType:
type: string
enum: [origin, destination]
enum: [home, commercial, destination, virtual]
customerId:
type: string
format: gid
originType:
type: string
enum: [home, commercial]
name:
type: string
fullAddress:
Expand All @@ -23,7 +20,6 @@ properties:
required:
- metafieldId
- locationType
- originType
- customerId
- name
- fullAddress
Expand Down
6 changes: 1 addition & 5 deletions openapi/paths/customer/location/create/body.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ properties:
type: string
fullAddress:
type: string
originType:
type: string
enum: [home, commercial]
distanceForFree:
type: number
distanceHourlyRate:
Expand All @@ -21,11 +18,10 @@ properties:
type: number
locationType:
type: string
enum: [origin, destination]
enum: [home, commercial, destination, virtual]
required:
- name
- fullAddress
- originType
- distanceForFree
- distanceHourlyRate
- fixedRatePerKm
Expand Down
4 changes: 0 additions & 4 deletions openapi/paths/customer/location/update/body.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ properties:
type: string
fullAddress:
type: string
originType:
type: string
enum: [home, commercial]
distanceForFree:
type: number
distanceHourlyRate:
Expand All @@ -22,7 +19,6 @@ properties:
required:
- name
- fullAddress
- originType
- distanceForFree
- distanceHourlyRate
- fixedRatePerKm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@ items:
type: string
locationType:
type: string
enum: [origin, destination]
originType:
type: string
enum: [home, commercial]
enum: [home, commercial, destination, virtual]
required:
- metafieldId
- location
- locationType
- originType
6 changes: 1 addition & 5 deletions openapi/paths/user/filters/payload.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,12 @@ properties:
type: string
locationType:
type: string
enum: [origin, destination]
originType:
type: string
enum: [home, commercial]
enum: [home, commercial, destination, virtual]
count:
type: integer
required:
- city
- locationType
- originType
- count
availableDays:
type: array
Expand Down
4 changes: 1 addition & 3 deletions openapi/paths/user/search/body.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@ properties:
type: string
locationType:
type: string
originType:
type: string
enum: [home, commercial, destination, virtual]
required:
- city
- locationType
- originType
days:
type: array
items:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { CustomerServiceGet } from "~/functions/customer/services/customer/get";
import { LocationOriginTypes, LocationTypes } from "~/functions/location";
import { ScheduleModel } from "~/functions/schedule";
import { UserScheduleServiceLocationsList } from "~/functions/user/services/schedule/locations-list";
import { shopifyRest } from "~/library/shopify/rest";
Expand Down Expand Up @@ -52,26 +51,11 @@ export const updateArticle = async ({
tags.push(
`city-${locations.map((l) => l.city.toLowerCase()).join(", city-")}`
);
const destination = locations.find(
(l) => l.locationType === LocationTypes.DESTINATION
tags.push(
`location_type-${locations
.map((l) => l.locationType)
.join(", location_type-")}`
);
if (destination) {
tags.push("location-destination");
} else {
const originTypeHome = locations.find(
(l) => l.originType === LocationOriginTypes.HOME
);
if (originTypeHome) {
tags.push("location-home");
}

const originTypeSalon = locations.find(
(l) => l.originType === LocationOriginTypes.COMMERCIAL
);
if (originTypeSalon) {
tags.push("location-salon");
}
}
}

tags.push(`gender-${user.gender}`);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LocationOriginTypes, LocationTypes } from "~/functions/location";
import { LocationTypes } from "~/functions/location";
import { createLocation } from "~/library/jest/helpers/location";
import { ensureType } from "~/library/jest/helpers/mock";
import { shopifyAdmin } from "~/library/shopify";
Expand Down Expand Up @@ -38,8 +38,7 @@ describe("CustomerLocationCreateOrchestration", () => {
const location = await createLocation({
name: "Falafel",
fullAddress: "Sigridsvej 45, 1. th, 8220 Brabrand",
originType: LocationOriginTypes.COMMERCIAL,
locationType: LocationTypes.ORIGIN,
locationType: LocationTypes.HOME,
customerId: 12,
distanceHourlyRate: 1,
fixedRatePerKm: 10,
Expand Down Expand Up @@ -73,10 +72,6 @@ describe("CustomerLocationCreateOrchestration", () => {
value: coordinates.country,
key: "country",
},
{
value: location.originType,
key: "origin_type",
},
{
value: location.distanceForFree.toString(),
key: "distance_for_free",
Expand Down Expand Up @@ -139,10 +134,6 @@ describe("CustomerLocationCreateOrchestration", () => {
value: location.country,
key: "country",
},
{
value: location.originType,
key: "origin_type",
},
{
value: location.distanceForFree.toString(),
key: "distance_for_free",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ export const createLocationMetafield = async ({
key: "country",
value: location.country,
},
{
key: "origin_type",
value: location.originType,
},
{
key: "distance_for_free",
value: location.distanceForFree.toString(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LocationOriginTypes, LocationTypes } from "~/functions/location";
import { LocationTypes } from "~/functions/location";
import { createLocation } from "~/library/jest/helpers/location";
import { ensureType } from "~/library/jest/helpers/mock";
import { shopifyAdmin } from "~/library/shopify";
Expand Down Expand Up @@ -38,8 +38,7 @@ describe("CustomerLocationUpdateOrchestration", () => {
const location = await createLocation({
name: "Falafel",
fullAddress: "Sigridsvej 45, 1. th, 8220 Brabrand",
originType: LocationOriginTypes.COMMERCIAL,
locationType: LocationTypes.ORIGIN,
locationType: LocationTypes.SALON,
customerId: 12,
distanceHourlyRate: 1,
fixedRatePerKm: 10,
Expand Down Expand Up @@ -71,10 +70,6 @@ describe("CustomerLocationUpdateOrchestration", () => {
value: coordinates.country,
key: "country",
},
{
value: location.originType,
key: "origin_type",
},
{
value: location.distanceForFree.toString(),
key: "distance_for_free",
Expand Down Expand Up @@ -137,10 +132,6 @@ describe("CustomerLocationUpdateOrchestration", () => {
value: location.country,
key: "country",
},
{
value: location.originType,
key: "origin_type",
},
{
value: location.distanceForFree.toString(),
key: "distance_for_free",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ export const updateLocationMetafield = async ({
key: "country",
value: location.country,
},
{
key: "origin_type",
value: location.originType,
},
{
key: "distance_for_free",
value: location.distanceForFree.toString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,11 @@ describe("CustomerProductUpdateOrchestration", () => {
customerId: user.customerId,
metafieldId: `gid://${faker.number.int({ min: 1, max: 5 })}`,
});

const product = getProductObject({
locations: [
getDumbLocationObject({
...location,
locationType: location.locationType,
location: location._id,
metafieldId: location.metafieldId,
}),
Expand Down Expand Up @@ -187,6 +188,12 @@ describe("CustomerProductUpdateOrchestration", () => {
data: mockProductUpdate,
});

const tagDays = [];
const days = newSchedule.slots.map((slot) => slot.day.toLowerCase());
if (days.length > 0) {
tagDays.push(`day-${days.join(", day-")}`);
}

await updateProduct({
customerId,
productId: product.productId,
Expand All @@ -203,6 +210,8 @@ describe("CustomerProductUpdateOrchestration", () => {
)}`,
`product-${product.productHandle}`,
`scheduleid-${newSchedule._id}`,
`location_type-${location.locationType}`,
...tagDays,
`locationid-${product.locations[0].location}`,
`city-${location.city.replace(/ /g, "-").toLowerCase()}`,
];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { CustomerServiceGet } from "~/functions/customer/services/customer/get";
import { PRODUCT_FRAGMENT } from "~/functions/customer/services/product/add";
import { CustomerProductServiceGet } from "~/functions/customer/services/product/get";
import { LocationModel } from "~/functions/location";
import { ScheduleModel } from "~/functions/schedule";
import { NotFoundError } from "~/library/handler";
Expand All @@ -18,12 +17,36 @@ export const updateProduct = async ({
customerId,
});

const { scheduleMetafieldId, scheduleName, scheduleId, ...product } =
await CustomerProductServiceGet({
customerId,
productId,
});
const schedule = await ScheduleModel.findOne({
customerId,
products: {
$elemMatch: {
productId,
},
},
}).orFail(
new NotFoundError([
{
code: "custom",
message: "PRODUCT_NOT_FOUND",
path: ["productId"],
},
])
);

const product = schedule.products.find((p) => p.productId === productId);

if (!product) {
throw new NotFoundError([
{
code: "custom",
message: "PRODUCT_NOT_FOUND",
path: ["productId"],
},
]);
}

// We dont want to show duplicate products in the treatment page, so we pick the one that are default to the visitor
const totalCountOfDefault = await ScheduleModel.aggregate([
{
$match: {
Expand Down Expand Up @@ -90,6 +113,20 @@ export const updateProduct = async ({
])
);

const tags = [];
if (locations.length > 0) {
tags.push(
`location_type-${locations
.map((l) => l.locationType)
.join(", location_type-")}`
);
}

const days = schedule.slots.map((slot) => slot.day.toLowerCase());
if (days.length > 0) {
tags.push(`day-${days.join(", day-")}`);
}

const variables = {
title: product.title,
descriptionHtml: product.descriptionHtml || "ads",
Expand Down Expand Up @@ -129,7 +166,7 @@ export const updateProduct = async ({
},
{
id: product?.locationsMetafieldId,
value: JSON.stringify(locations.map((p) => p.metafieldId)),
value: JSON.stringify(product.locations.map((p) => p.metafieldId)),
},
{
id: product?.user?.metaobjectId,
Expand All @@ -145,7 +182,7 @@ export const updateProduct = async ({
},
{
id: product?.scheduleIdMetafieldId,
value: scheduleMetafieldId, //reference to scheduleModel.metafieldId, product.scheduleIdMetafieldId reference to product-schedule-metafieldId
value: schedule.metafieldId,
},
],
tags: [
Expand All @@ -156,9 +193,10 @@ export const updateProduct = async ({
`parentid-${product.parentId}`,
`productid-${product.productId}`,
`product-${product.productHandle}`,
`scheduleid-${scheduleId}`,
`scheduleid-${schedule._id}`,
]
.concat(locations.map((l) => `locationid-${l._id}`))
.concat(tags)
.concat(product.locations.map((l) => `locationid-${l.location}`))
.concat(
Array.from(
new Set(
Expand Down
3 changes: 3 additions & 0 deletions src/functions/customer/orchestrations/schedule/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ const orchestrator: df.OrchestrationHandler = function* (
activityType<typeof updateScheduleMetafield>(input)
);

// TODO:
// Since days could be changed, we might go through all products and update the days tags for them that are referenced to this schedule

return { metafield };
};

Expand Down
1 change: 0 additions & 1 deletion src/functions/customer/services/booking/aggregation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ export const bookingAggregation: PipelineStage[] = [
$project: {
name: 1,
fullAddress: 1,
originType: 1,
locationType: 1,
},
},
Expand Down
Loading

0 comments on commit 0d3151c

Please sign in to comment.