-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(core): refactor merchant data structure
chore: remove redundant describe test: first integration test for add merchant chore: add migration (untested yet)
- Loading branch information
Nicolas Burtey
committed
Feb 1, 2024
1 parent
ee42e71
commit b3f5a10
Showing
34 changed files
with
638 additions
and
259 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
mutation businessDeleteMapInfo($input: BusinessDeleteMapInfoInput!) { | ||
businessDeleteMapInfo(input: $input) { | ||
errors { | ||
message | ||
} | ||
} | ||
} |
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,18 @@ | ||
mutation businessUpdateMapInfo($input: BusinessUpdateMapInfoInput!) { | ||
businessUpdateMapInfo(input: $input) { | ||
errors { | ||
message | ||
} | ||
merchant { | ||
id | ||
title | ||
coordinates { | ||
latitude | ||
longitude | ||
} | ||
username | ||
validated | ||
createdAt | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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,38 @@ | ||
import { checkedToUsername } from "@/domain/accounts" | ||
import { MerchantsRepository } from "@/services/mongoose" | ||
|
||
export const deleteBusinessMapInfo = async ({ | ||
id, | ||
}: { | ||
id: MerchantId | ||
}): Promise<void | ApplicationError> => { | ||
const merchantsRepo = MerchantsRepository() | ||
|
||
const result = await merchantsRepo.remove(id) | ||
if (result instanceof Error) return result | ||
|
||
return | ||
} | ||
|
||
export const deleteMerchantByUsername = async ({ | ||
username, | ||
}: { | ||
username: string | ||
}): Promise<void | ApplicationError> => { | ||
const merchantsRepo = MerchantsRepository() | ||
|
||
const usernameChecked = checkedToUsername(username) | ||
if (usernameChecked instanceof Error) return usernameChecked | ||
|
||
const merchants = await merchantsRepo.findByUsername(usernameChecked) | ||
if (merchants instanceof Error) return merchants | ||
|
||
if (merchants.length === 0) return | ||
|
||
for (const merchant of merchants) { | ||
const result = await merchantsRepo.remove(merchant.id) | ||
if (result instanceof Error) return result | ||
} | ||
|
||
return | ||
} |
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,10 @@ | ||
import { MerchantsRepository } from "@/services/mongoose" | ||
|
||
export * from "./update-business-map-info" | ||
export * from "./delete-business-map-info" | ||
|
||
const merchants = MerchantsRepository() | ||
|
||
export const getMerchantsMapMarkers = async () => { | ||
return merchants.listForMap() | ||
} |
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,45 @@ | ||
import { checkedCoordinates, checkedMapTitle, checkedToUsername } from "@/domain/accounts" | ||
import { CouldNotFindMerchantFromUsernameError } from "@/domain/errors" | ||
import { MerchantsRepository } from "@/services/mongoose" | ||
|
||
export const updateBusinessMapInfo = async ({ | ||
username, | ||
coordinates: { latitude, longitude }, | ||
title, | ||
}: { | ||
username: string | ||
coordinates: { latitude: number; longitude: number } | ||
title: string | ||
}): Promise<BusinessMapMarker | ApplicationError> => { | ||
const merchantsRepo = MerchantsRepository() | ||
|
||
const usernameChecked = checkedToUsername(username) | ||
if (usernameChecked instanceof Error) return usernameChecked | ||
|
||
const coordinates = checkedCoordinates({ latitude, longitude }) | ||
if (coordinates instanceof Error) return coordinates | ||
|
||
const titleChecked = checkedMapTitle(title) | ||
if (titleChecked instanceof Error) return titleChecked | ||
|
||
const merchants = await merchantsRepo.findByUsername(usernameChecked) | ||
|
||
if (merchants instanceof CouldNotFindMerchantFromUsernameError) { | ||
return merchantsRepo.create({ | ||
username: usernameChecked, | ||
coordinates, | ||
title: titleChecked, | ||
validated: true, | ||
}) | ||
} else if (merchants instanceof Error) { | ||
return merchants | ||
} | ||
|
||
// TODO: manage multiple merchants for a single username | ||
const merchant = merchants[0] | ||
|
||
merchant.coordinates = coordinates | ||
merchant.title = titleChecked | ||
|
||
return merchantsRepo.update(merchant) | ||
} |
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
Oops, something went wrong.