From 03f319dab545e9870ba1be3bc3f8e379eadc4821 Mon Sep 17 00:00:00 2001 From: vanpho93 Date: Sat, 18 Mar 2023 10:28:10 +0700 Subject: [PATCH] feat: change store hours to array type Signed-off-by: vanpho93 --- .../api-plugin-location/src/preStartup.js | 16 +++++ .../src/schemas/schema.graphql | 62 ++++++++++++++++--- .../api-plugin-location/src/simpleSchemas.js | 54 +++++++++------- 3 files changed, 101 insertions(+), 31 deletions(-) create mode 100644 packages/api-plugin-location/src/preStartup.js diff --git a/packages/api-plugin-location/src/preStartup.js b/packages/api-plugin-location/src/preStartup.js new file mode 100644 index 0000000000..c49b35d0ac --- /dev/null +++ b/packages/api-plugin-location/src/preStartup.js @@ -0,0 +1,16 @@ +import { Location } from "./simpleSchemas.js"; + +/** + * @summary Called before startup + * @param {Object} context Startup context + * @returns {undefined} + */ +export default async function locationPreStartup(context) { + const { simpleSchemas: { FulfillmentMethod } } = context; + + Location.extend({ + "fulfillmentMethods.$": { + type: FulfillmentMethod + } + }); +} diff --git a/packages/api-plugin-location/src/schemas/schema.graphql b/packages/api-plugin-location/src/schemas/schema.graphql index 5ce5d6dd1e..5c33b5a436 100644 --- a/packages/api-plugin-location/src/schemas/schema.graphql +++ b/packages/api-plugin-location/src/schemas/schema.graphql @@ -9,15 +9,26 @@ type LocationAddress { city: String! " The State/Province/Region of the address." - region: String! + region: String " The ZIP/Postal Code of the address." - postal: String! + postal: String " The ISO 3166-1 alpha-2 country code of the address." country: String! } +type LocationStoreHour { + " The day of the week [monday, tuesday, wednesday, thursday, friday, saturday, sunday]." + day: String! + + " The open time of the day." + open: String! + + " The close time of the day." + close: String! +} + type Location { " The ID of the location." _id: ID! @@ -44,7 +55,7 @@ type Location { localFulfillmentOnly: Boolean " The open hours of the type store location." - storeHours: Int + storeHours: [LocationStoreHour] " The pickup hours of the type store location." storePickupHours: Int @@ -127,7 +138,18 @@ input LocationFilter { isArchived: Boolean } -input LocationAddressInput { +input LocationStoreHourInput { + " The day of the week [monday, tuesday, wednesday, thursday, friday, saturday, sunday]." + day: String! + + " The open time of the day." + open: String! + + " The close time of the day." + close: String! +} + +input LocationCreateAddressInput { " The first line of the address." address1: String! @@ -138,10 +160,10 @@ input LocationAddressInput { city: String! " The State/Province/Region of the address." - region: String! + region: String " The ZIP/Postal Code of the address." - postal: String! + postal: String " The ISO 3166-1 alpha-2 country code of the address." country: String! @@ -162,7 +184,7 @@ input LocationCreateInput { type: String! " The address of the location." - address: LocationAddressInput! + address: LocationCreateAddressInput! " The phone number of the location." phoneNumber: String! @@ -174,7 +196,7 @@ input LocationCreateInput { localFulfillmentOnly: Boolean " The open hours of the type store location." - storeHours: Int + storeHours: [LocationStoreHourInput] " The pickup hours of the type store location." storePickupHours: Int @@ -186,6 +208,26 @@ input LocationCreateInput { enabled: Boolean } +input LocationUpdateAddressInput { + " The first line of the address." + address1: String + + " The second line of the address." + address2: String + + " The city of the address." + city: String + + " The State/Province/Region of the address." + region: String + + " The ZIP/Postal Code of the address." + postal: String + + " The ISO 3166-1 alpha-2 country code of the address." + country: String +} + input LocationUpdateInput { " The location ID" _id: ID! @@ -203,7 +245,7 @@ input LocationUpdateInput { type: String " The address of the location." - address: LocationAddressInput + address: LocationUpdateAddressInput " The phone number of the location." phoneNumber: String @@ -215,7 +257,7 @@ input LocationUpdateInput { localFulfillmentOnly: Boolean " The open hours of the type store location." - storeHours: Int + storeHours: [LocationStoreHourInput] " The pickup hours of the type store location." storePickupHours: Int diff --git a/packages/api-plugin-location/src/simpleSchemas.js b/packages/api-plugin-location/src/simpleSchemas.js index 8a90c98be1..c4ed1f187b 100644 --- a/packages/api-plugin-location/src/simpleSchemas.js +++ b/packages/api-plugin-location/src/simpleSchemas.js @@ -25,7 +25,8 @@ export const LocationAddress = new SimpleSchema({ }, region: { label: "State/Province/Region", - type: String + type: String, + optional: true }, postal: { label: "ZIP/Postal Code", @@ -47,17 +48,26 @@ export const LocationAddress = new SimpleSchema({ } }); +export const StoreHour = new SimpleSchema({ + day: { + type: String, + allowedValues: ["monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"], + }, + open: String, + close: String +}); + export const Location = new SimpleSchema({ - _id: String, - shopId: String, - name: String, - identifier: String, - type: { + "_id": String, + "shopId": String, + "name": String, + "identifier": String, + "type": { type: String, allowedValues: ["warehouse", "store", "dropship", "marketplace"] }, - address: LocationAddress, - phoneNumber: { + "address": LocationAddress, + "phoneNumber": { type: String, custom() { const country = this.field("address.country"); @@ -70,40 +80,42 @@ export const Location = new SimpleSchema({ return this.value.startsWith(phone) ? true : `The phone number must start with ${phone} for ${name}`; } }, - fulfillmentMethod: { + "fulfillmentMethod": { type: String, allowedValues: ["shipping", "pickup", "ship-to-store", "local-delivery"] }, - localFulfillmentOnly: { + "localFulfillmentOnly": { type: Boolean, defaultValue: false, optional: true }, - storeHours: { - type: Number, - min: 0, - max: 24, - optional: true + "storeHours": { + type: Array, + optional: true, + maxCount: 7 + }, + "storeHours.$": { + type: StoreHour }, - storePickupHours: { + "storePickupHours": { type: Number, allowedValues: [2, 4, 6, 12, 24, 48, 120, 178, 336], optional: true }, - storePickupInstructions: { + "storePickupInstructions": { type: String, optional: true }, - enabled: { + "enabled": { type: Boolean, defaultValue: false, optional: true }, - isArchived: { + "isArchived": { type: Boolean, defaultValue: false, optional: true }, - createdAt: Date, - updatedAt: Date + "createdAt": Date, + "updatedAt": Date });