-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adding suggest and approve endpoint for the map
- Loading branch information
Nicolas Burtey
committed
Feb 3, 2024
1 parent
661b999
commit 5367f52
Showing
24 changed files
with
356 additions
and
143 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,11 @@ | ||
mutation merchantMapValidate($input: MerchantMapValidateInput!) { | ||
merchantMapValidate(input: $input) { | ||
errors { | ||
message | ||
} | ||
merchant { | ||
id | ||
validated | ||
} | ||
} | ||
} |
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,5 @@ | ||
query merchantsPendingApproval { | ||
merchantsPendingApproval { | ||
id | ||
} | ||
} |
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
7 changes: 3 additions & 4 deletions
7
bats/admin-gql/business-update-map-info.gql → bats/gql/merchant-map-suggest.gql
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,18 +1,17 @@ | ||
mutation businessUpdateMapInfo($input: BusinessUpdateMapInfoInput!) { | ||
businessUpdateMapInfo(input: $input) { | ||
mutation merchantMapSuggest($input: MerchantMapSuggestInput!) { | ||
merchantMapSuggest(input: $input) { | ||
errors { | ||
message | ||
} | ||
merchant { | ||
id | ||
validated | ||
title | ||
coordinates { | ||
latitude | ||
longitude | ||
} | ||
username | ||
validated | ||
createdAt | ||
} | ||
} | ||
} |
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,13 @@ | ||
import { MerchantsRepository } from "@/services/mongoose" | ||
|
||
export const approveMerchantById = async ( | ||
id: MerchantId, | ||
): Promise<BusinessMapMarker | ApplicationError> => { | ||
const merchantsRepo = MerchantsRepository() | ||
|
||
const merchant = await merchantsRepo.findById(id) | ||
if (merchant instanceof Error) return merchant | ||
|
||
merchant.validated = true | ||
return merchantsRepo.update(merchant) | ||
} |
File renamed without changes.
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,10 +1,15 @@ | ||
import { MerchantsRepository } from "@/services/mongoose" | ||
|
||
export * from "./update-business-map" | ||
export * from "./delete-business-map" | ||
export * from "./suggest-merchant-map" | ||
export * from "./delete-merchant-map" | ||
export * from "./approve-merchant-map" | ||
|
||
const merchants = MerchantsRepository() | ||
|
||
export const getMerchantsMapMarkers = async () => { | ||
return merchants.listForMap() | ||
} | ||
|
||
export const getMerchantsPendingApproval = async () => { | ||
return merchants.listPendingApproval() | ||
} |
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,36 @@ | ||
import { checkedCoordinates, checkedMapTitle, checkedToUsername } from "@/domain/accounts" | ||
import { AccountsRepository, MerchantsRepository } from "@/services/mongoose" | ||
|
||
export const suggestMerchantMap = 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 accountRepository = AccountsRepository() | ||
const account = await accountRepository.findByUsername(usernameChecked) | ||
if (account instanceof Error) { | ||
return account | ||
} | ||
|
||
return merchantsRepo.create({ | ||
username: usernameChecked, | ||
coordinates, | ||
title: titleChecked, | ||
validated: false, | ||
}) | ||
} |
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 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
44 changes: 44 additions & 0 deletions
44
core/api/src/graphql/admin/root/mutation/merchant-map-validate.ts
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,44 @@ | ||
import { Merchants } from "@/app" | ||
import { mapAndParseErrorForGqlResponse } from "@/graphql/error-map" | ||
import { GT } from "@/graphql/index" | ||
import MerchantPayload from "@/graphql/shared/types/payload/merchant" | ||
|
||
const MerchantMapValidateInput = GT.Input({ | ||
name: "MerchantMapValidateInput", | ||
fields: () => ({ | ||
id: { | ||
// TODO: MerchantID? | ||
type: GT.NonNullID, | ||
}, | ||
}), | ||
}) | ||
|
||
const MerchantMapValidate = GT.Field<null, GraphQLAdminContext>({ | ||
extensions: { | ||
complexity: 120, | ||
}, | ||
type: GT.NonNull(MerchantPayload), | ||
args: { | ||
input: { type: GT.NonNull(MerchantMapValidateInput) }, | ||
}, | ||
resolve: async (_, args) => { | ||
const { id } = args.input | ||
|
||
if (id instanceof Error) { | ||
return { errors: [{ message: id.message }] } | ||
} | ||
|
||
const merchant = await Merchants.approveMerchantById(id) | ||
|
||
if (merchant instanceof Error) { | ||
return { errors: [mapAndParseErrorForGqlResponse(merchant)] } | ||
} | ||
|
||
return { | ||
errors: [], | ||
merchant, | ||
} | ||
}, | ||
}) | ||
|
||
export default MerchantMapValidate |
22 changes: 22 additions & 0 deletions
22
core/api/src/graphql/admin/root/query/merchants-pending-approval-listing.ts
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,22 @@ | ||
import { GT } from "@/graphql/index" | ||
|
||
import { Merchants } from "@/app" | ||
import { mapError } from "@/graphql/error-map" | ||
import Merchant from "@/graphql/shared/types/object/merchant" | ||
|
||
const MerchantsPendingApprovalQuery = GT.Field({ | ||
type: GT.List(Merchant), | ||
resolve: async (_, { id }) => { | ||
if (id instanceof Error) throw id | ||
|
||
const merchants = await Merchants.getMerchantsPendingApproval() | ||
|
||
if (merchants instanceof Error) { | ||
throw mapError(merchants) | ||
} | ||
|
||
return merchants | ||
}, | ||
}) | ||
|
||
export default MerchantsPendingApprovalQuery |
Oops, something went wrong.