-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1183f73
commit d1517df
Showing
14 changed files
with
183 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,70 @@ | ||
import {Order, OrderStatus} from "./types"; | ||
import { getOrderStore } from "./store"; | ||
import {ShipmentFrom, ShipmentLocation, ShipmentTo} from "../shipment"; | ||
|
||
export interface ListOrdersInput { | ||
status?: OrderStatus; | ||
from?: ShipmentFrom; | ||
to?: ShipmentTo; | ||
} | ||
|
||
export async function listOrders({ status }: ListOrdersInput = {}): Promise< | ||
export async function listOrders({ status, from, to }: ListOrdersInput = {}): Promise< | ||
Order[] | ||
> { | ||
const store = getOrderStore(); | ||
let values = await store.values(); | ||
if (from) { | ||
values = values.filter(value => { | ||
if (!value.from) return false; | ||
return isShipmentLocationMatch(from, value.from); | ||
}); | ||
} | ||
if (to) { | ||
values = values.filter(value => { | ||
if (!value.to) return false; | ||
return isShipmentLocationMatch(to, value.to); | ||
}); | ||
} | ||
if (status) { | ||
values = values.filter(value => value.status === status); | ||
} | ||
return values.sort((a, b) => new Date(a.createdAt).getTime() < new Date(b.createdAt).getTime() ? -1 : 1) | ||
|
||
|
||
} | ||
|
||
function isShipmentLocationMatch(base: ShipmentLocation, match: ShipmentLocation) { | ||
return ( | ||
( | ||
!base.organisationId || | ||
base.organisationId === match.organisationId | ||
) && | ||
( | ||
!base.locationId || | ||
base.locationId === match.locationId | ||
) && | ||
( | ||
!base.inventoryId || | ||
base.inventoryId === match.inventoryId | ||
) && | ||
( | ||
!base.inventoryProductId || | ||
base.inventoryProductId === match.inventoryProductId | ||
) && | ||
( | ||
!base.countryCode || | ||
base.countryCode === match.countryCode | ||
) && | ||
( | ||
!base.address || | ||
( | ||
match.address && | ||
base.address.length === match.address.length && | ||
( | ||
!base.address.length || | ||
base.address.every((value, index) => match.address[index] === value) | ||
) | ||
) | ||
) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,13 @@ | ||
import { v4 } from "uuid"; | ||
import { OrganisationData, Organisation } from "./types"; | ||
import { getOrganisationStore } from "./store"; | ||
import { setOrganisation } from "./set-organisation"; | ||
|
||
export interface AddOrganisationInput extends OrganisationData {} | ||
|
||
export async function addOrganisation( | ||
data: AddOrganisationInput | ||
): Promise<Organisation> { | ||
const store = getOrganisationStore(); | ||
const organisationId = v4(); | ||
const createdAt = new Date().toISOString(); | ||
const organisation: Organisation = { | ||
export async function addOrganisation(data: OrganisationData): Promise<Organisation> { | ||
return setOrganisation({ | ||
...data, | ||
organisationId, | ||
organisationId: v4(), | ||
approved: false, | ||
approvedAt: undefined, | ||
approvedByUserId: undefined, | ||
createdAt, | ||
updatedAt: createdAt, | ||
}; | ||
await store.set(organisationId, organisation); | ||
return organisation; | ||
approvedByUserId: undefined | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { v4 } from "uuid"; | ||
import { Organisation, PartialOrganisation } from "./types"; | ||
import { getOrganisationStore } from "./store"; | ||
|
||
export async function setOrganisation( | ||
data: PartialOrganisation | ||
): Promise<Organisation> { | ||
const store = getOrganisationStore(); | ||
const organisationId = data.organisationId || v4(); | ||
const updatedAt = new Date().toISOString(); | ||
const createdAt = data.createdAt || updatedAt; | ||
const organisation: Organisation = { | ||
approved: false, | ||
approvedAt: undefined, | ||
approvedByUserId: undefined, | ||
...data, | ||
organisationId, | ||
createdAt, | ||
updatedAt, | ||
}; | ||
await store.set(organisationId, organisation); | ||
return organisation; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
// File generated by scripts/pre-build.js | ||
|
||
export const commit = "c55f5e8843ad844cbe27bb2b6bb5043cb6256444"; | ||
export const commitShort = "c55f5e8"; | ||
export const commit = "1183f730ea35ee842cbc4d1be6a5fef5c515d156"; | ||
export const commitShort = "1183f73"; | ||
export const commitAuthor = "Fabian Cook"; | ||
export const commitEmail = "[email protected]"; | ||
export const commitMessage = "Public offers and products, #21, #1"; | ||
export const commitAt = "2023-06-18T04:56:58.000Z"; | ||
export const secondsBetweenCommitAndBuild = 107.2; | ||
export const minutesBetweenCommitAndBuild = 1.79; | ||
export const timeBetweenCommitAndBuild = "1 minutes and 47 seconds"; | ||
export const secondsBetweenCommitAndBuild = 17513.54; | ||
export const minutesBetweenCommitAndBuild = 291.89; | ||
export const timeBetweenCommitAndBuild = "291 minutes and 53 seconds"; | ||
// Variables to be replaced after tests | ||
export const secondsBetweenCommitAndTestCompletion = ""; | ||
export const minutesBetweenCommitAndTestCompletion = ""; | ||
export const timeBetweenCommitAndTestCompletion = ""; | ||
export const secondsBetweenCommitAndTestCompletion = "17547.92"; | ||
export const minutesBetweenCommitAndTestCompletion = "292.47"; | ||
export const timeBetweenCommitAndTestCompletion = "292 minutes and 27 seconds"; |
Oops, something went wrong.