Feat/improve overview of gift cards (#297)

* modified list-gift-card

* added search with relations to gift cards to allow for proper lookup

* removed new line

* created skeleton for testing

* began impl. tests

* added more test

* finished tests

* reverted failed changes

* updated tests to accomodate re-introduced additions

* removed VSCode settings file

* updated according to comments

* corrected use of findOneWithRelations for gift-card

* corrected parsing to be postgresql instead of an if-statement for gift-card

* changed bits and pieces
This commit is contained in:
Sebastian Mateos Nicolajsen
2021-07-08 09:59:59 +02:00
committed by GitHub
parent 0c96813e2f
commit 92caff845e
6 changed files with 385 additions and 8 deletions
@@ -33,7 +33,10 @@ export const defaultFields = [
"metadata",
]
export const defaultRelations = ["region"]
export const defaultRelations = [
"region",
"order",
]
export const allowedFields = [
"id",
@@ -1,3 +1,4 @@
import { MedusaError, Validator } from "medusa-core-utils"
import { defaultFields, defaultRelations } from "./"
/**
@@ -21,14 +22,23 @@ import { defaultFields, defaultRelations } from "./"
*/
export default async (req, res) => {
try {
const limit = parseInt(req.query.limit) || 50
const offset = parseInt(req.query.offset) || 0
const selector = {}
if ("q" in req.query) {
selector.q = req.query.q
}
const giftCardService = req.scope.resolve("giftCardService")
const giftCards = await giftCardService.list(selector, {
select: defaultFields,
relations: defaultRelations,
order: { created_at: "DESC" },
limit: limit,
skip: offset,
})
res.status(200).json({ gift_cards: giftCards })
@@ -1,4 +1,5 @@
import { MedusaError, Validator } from "medusa-core-utils"
import { defaultFields, defaultRelations } from "./"
/**
* @oas [post] /gift-cards/{id}