Skip to content

Commit

Permalink
feat: adding suggest and approve endpoint for the map
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Burtey committed Feb 3, 2024
1 parent f548dc8 commit c4f66a6
Show file tree
Hide file tree
Showing 27 changed files with 418 additions and 207 deletions.
7 changes: 0 additions & 7 deletions bats/admin-gql/business-delete-map-info.gql

This file was deleted.

7 changes: 7 additions & 0 deletions bats/admin-gql/merchant-map-delete.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
mutation merchantMapDelete($input: MerchantMapDeleteInput!) {
merchantMapDelete(input: $input) {
errors {
message
}
}
}
11 changes: 11 additions & 0 deletions bats/admin-gql/merchant-map-validate.gql
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
}
}
}
5 changes: 5 additions & 0 deletions bats/admin-gql/merchants-pending-approval.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
query merchantsPendingApproval {
merchantsPendingApproval {
id
}
}
50 changes: 39 additions & 11 deletions bats/core/api/merchant.bats
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ setup_file() {
login_admin
}

@test "merchant: add a merchant with admin api" {
admin_token="$(read_value 'admin.token')"
@test "merchant: suggest a merchant" {
token_name='merchant'

latitude=40.712776
longitude=-74.005974
title="My Merchant"
Expand All @@ -28,28 +29,55 @@ setup_file() {
'{input: {latitude: ($latitude | tonumber), longitude: ($longitude | tonumber), title: $title, username: $username}}'
)

exec_admin_graphql $admin_token 'business-update-map-info' "$variables"
latitude_result="$(graphql_output '.data.businessUpdateMapInfo.merchant.coordinates.latitude')"
exec_graphql "$token_name" 'merchant-map-suggest' "$variables"
latitude_result="$(graphql_output '.data.merchantMapSuggest.merchant.coordinates.latitude')"
[[ "$latitude_result" == "$latitude" ]] || exit 1

# no merchant visible yet
exec_graphql 'anon' 'business-map-markers'
map_markers="$(graphql_output)"
markers_length=$(echo "$map_markers" | jq '.data.businessMapMarkers | length')

[[ $markers_length -eq 0 ]] || exit 1
}

@test "merchant: can query merchants" {
@test "merchant: listing and approving merchant waiting for approval" {
admin_token="$(read_value 'admin.token')"
local username="$(read_value merchant.username)"

exec_admin_graphql $admin_token 'merchants-pending-approval'
id="$(graphql_output '.data.merchantsPendingApproval[0].id')"
[[ "$id" != "null" && "$id" != "" ]] || exit 1
cache_value 'merchant.id' "$id"

# validating merchant
variables=$(jq -n \
--arg id "$id" \
'{input: {id: $id}}'
)
exec_admin_graphql $admin_token 'merchant-map-validate' "$variables"
validate_status="$(graphql_output '.data.merchantMapValidate.merchant.validated')"
[[ "$validate_status" == "true" ]] || exit 1

# merchant is now visible from public api
local username="$(read_value merchant.username)"
exec_graphql 'anon' 'business-map-markers'
fetch_username="$(graphql_output '.data.businessMapMarkers[0].username')"
[[ $username = $fetch_username ]] || exit 1

markers=$(graphql_output '.data.businessMapMarkers')
markers_length=$(echo $markers | jq 'length')
[[ $markers_length -gt 0 ]] || exit 1
}

@test "merchant: delete merchant with admin api" {
admin_token="$(read_value 'admin.token')"
local username="$(read_value merchant.username)"

id="$(read_value merchant.id)"
variables=$(jq -n \
--arg username "$username" \
'{input: {username: $username}}'
--arg id "$id" \
'{input: {id: $id}}'
)

exec_admin_graphql $admin_token 'business-delete-map-info' "$variables"
exec_admin_graphql $admin_token 'merchant-map-delete' "$variables"

exec_graphql 'anon' 'business-map-markers'
map_markers="$(graphql_output)"
Expand Down
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
}
}
}
13 changes: 13 additions & 0 deletions core/api/src/app/merchants/approve-merchant-map.ts
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)
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { checkedToUsername } from "@/domain/accounts"
import { MerchantsRepository } from "@/services/mongoose"

export const deleteMerchantById = async ({
id,
}: {
id: MerchantId
}): Promise<true | ApplicationError> => {
export const deleteMerchantById = async (
id: MerchantId,
): Promise<true | ApplicationError> => {
const merchantsRepo = MerchantsRepository()

const result = await merchantsRepo.remove(id)
Expand Down
9 changes: 7 additions & 2 deletions core/api/src/app/merchants/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { MerchantsRepository } from "@/services/mongoose"

export * from "./update-business-map-info"
export * from "./delete-business-map-info"
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()
}
36 changes: 36 additions & 0 deletions core/api/src/app/merchants/suggest-merchant-map.ts
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,
})
}
45 changes: 0 additions & 45 deletions core/api/src/app/merchants/update-business-map-info.ts

This file was deleted.

8 changes: 4 additions & 4 deletions core/api/src/graphql/admin/mutations.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import UserUpdatePhoneMutation from "./root/mutation/user-update-phone"

import BusinessDeleteMapInfoMutation from "./root/mutation/delete-business-map"
import MerchantMapDeleteMutation from "./root/mutation/merchant-map-delete"
import MerchantMapValidateMutation from "./root/mutation/merchant-map-validate"

import AccountUpdateLevelMutation from "./root/mutation/account-update-level"
import AccountUpdateStatusMutation from "./root/mutation/account-update-status"
import AdminPushNotificationSendMutation from "./root/mutation/admin-push-notification-send"
import BusinessUpdateMapInfoMutation from "./root/mutation/business-update-map-info"

import { GT } from "@/graphql/index"

Expand All @@ -15,8 +15,8 @@ export const mutationFields = {
userUpdatePhone: UserUpdatePhoneMutation,
accountUpdateLevel: AccountUpdateLevelMutation,
accountUpdateStatus: AccountUpdateStatusMutation,
businessUpdateMapInfo: BusinessUpdateMapInfoMutation,
businessDeleteMapInfo: BusinessDeleteMapInfoMutation,
merchantMapValidate: MerchantMapValidateMutation,
merchantMapDelete: MerchantMapDeleteMutation,
adminPushNotificationSend: AdminPushNotificationSendMutation,
},
}
Expand Down
2 changes: 2 additions & 0 deletions core/api/src/graphql/admin/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import ListWalletIdsQuery from "./root/query/all-walletids"
import WalletQuery from "./root/query/wallet"
import AccountDetailsByAccountId from "./root/query/account-details-by-account-id"
import AccountDetailsByUserId from "./root/query/account-details-by-user-id"
import MerchantsPendingApprovalQuery from "./root/query/merchants-pending-approval-listing"

import { GT } from "@/graphql/index"

Expand All @@ -28,6 +29,7 @@ export const queryFields = {
lightningPayment: LightningPaymentQuery,
listWalletIds: ListWalletIdsQuery,
wallet: WalletQuery,
merchantsPendingApproval: MerchantsPendingApprovalQuery,
},
}

Expand Down
52 changes: 0 additions & 52 deletions core/api/src/graphql/admin/root/mutation/delete-business-map.ts

This file was deleted.

Loading

0 comments on commit c4f66a6

Please sign in to comment.