Skip to content

Commit

Permalink
feat: change store hours to array type
Browse files Browse the repository at this point in the history
Signed-off-by: vanpho93 <[email protected]>
  • Loading branch information
vanpho93 committed Mar 18, 2023
1 parent ac5df58 commit 03f319d
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 31 deletions.
16 changes: 16 additions & 0 deletions packages/api-plugin-location/src/preStartup.js
Original file line number Diff line number Diff line change
@@ -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
}
});
}
62 changes: 52 additions & 10 deletions packages/api-plugin-location/src/schemas/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand All @@ -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
Expand Down Expand Up @@ -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!

Expand All @@ -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!
Expand All @@ -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!
Expand All @@ -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
Expand All @@ -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!
Expand All @@ -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
Expand All @@ -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
Expand Down
54 changes: 33 additions & 21 deletions packages/api-plugin-location/src/simpleSchemas.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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");
Expand All @@ -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
});

0 comments on commit 03f319d

Please sign in to comment.