Merge branch 'develop' into feat/disabling-of-notification

This commit is contained in:
--list committed 2021-07-02 12:11:45 +02:00
commit 92710eb1de
27 files changed
+583 -70

No files matched your search

+2 -1
View File
@@ -5,10 +5,11 @@
export const MedusaErrorTypes = {
/** Errors stemming from the database */
DB_ERROR: "database_error",
DUPLICATE_ERROR: "duplicate_error",
INVALID_ARGUMENT: "invalid_argument",
INVALID_DATA: "invalid_data",
NOT_FOUND: "not_found",
NOT_ALLOWED: "not_allowed"
NOT_ALLOWED: "not_allowed",
}
/**
+1 -6
View File
@@ -3740,12 +3740,7 @@ lodash.sortby@^4.7.0:
resolved "https://registry.yarnpkg.com/lodash.sortby/-/lodash.sortby-4.7.0.tgz#edd14c824e2cc9c1e0b0a1b42bb5210516a42438"
integrity sha1-7dFMgk4sycHgsKG0K7UhBRakJDg=
lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.15:
version "4.17.20"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.20.tgz#b44a9b6297bcb698f1c51a3545a2b3b368d59c52"
integrity sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA==
lodash@^4.17.19:
lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.19:
version "4.17.21"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==
@@ -9,6 +9,9 @@ export default () => {
let statusCode = 500
switch (err.name) {
case MedusaError.Types.DUPLICATE_ERROR:
statusCode = 409
break
case MedusaError.Types.NOT_ALLOWED:
case MedusaError.Types.INVALID_DATA:
statusCode = 400
@@ -1,6 +1,7 @@
import { IdMap } from "medusa-test-utils"
import { request } from "../../../../../helpers/test-request"
import { CustomerServiceMock } from "../../../../../services/__mocks__/customer"
import { defaultFields, defaultRelations } from "../"
describe("POST /store/customers", () => {
describe("successfully creates a customer", () => {
@@ -34,7 +35,7 @@ describe("POST /store/customers", () => {
expect(CustomerServiceMock.retrieve).toHaveBeenCalledTimes(1)
expect(CustomerServiceMock.retrieve).toHaveBeenCalledWith(
IdMap.getId("lebron"),
{ relations: ["shipping_addresses"] }
{ relations: defaultRelations, select: defaultFields }
)
})
@@ -1,5 +1,6 @@
import { IdMap } from "medusa-test-utils"
import { request } from "../../../../../helpers/test-request"
import { defaultFields, defaultRelations } from "../"
import { CustomerServiceMock } from "../../../../../services/__mocks__/customer"
describe("POST /store/customers/:id", () => {
@@ -42,7 +43,7 @@ describe("POST /store/customers/:id", () => {
expect(CustomerServiceMock.retrieve).toHaveBeenCalledTimes(1)
expect(CustomerServiceMock.retrieve).toHaveBeenCalledWith(
IdMap.getId("lebron"),
{ relations: ["shipping_addresses"] }
{ relations: defaultRelations, select: defaultFields }
)
})
@@ -1,4 +1,5 @@
import { Validator, MedusaError } from "medusa-core-utils"
import { defaultRelations, defaultFields } from "./"
/**
* @oas [post] /customers/{id}/addresses
@@ -45,7 +46,8 @@ export default async (req, res) => {
let customer = await customerService.addAddress(id, value.address)
customer = await customerService.retrieve(id, {
relations: ["shipping_addresses"],
relations: defaultRelations,
select: defaultFields,
})
res.status(200).json({ customer })
@@ -1,6 +1,7 @@
import jwt from "jsonwebtoken"
import { Validator, MedusaError } from "medusa-core-utils"
import config from "../../../../config"
import { defaultRelations, defaultFields } from "./"
/**
* @oas [post] /customers
@@ -40,6 +41,7 @@ export default async (req, res) => {
if (error) {
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
}
try {
const customerService = req.scope.resolve("customerService")
let customer = await customerService.create(value)
@@ -50,7 +52,8 @@ export default async (req, res) => {
})
customer = await customerService.retrieve(customer.id, {
relations: ["shipping_addresses"],
relations: defaultRelations,
select: defaultFields,
})
res.status(200).json({ customer })
@@ -1,3 +1,5 @@
import { defaultRelations, defaultFields } from "./"
/**
* @oas [delete] /customers/{id}/addresses/{address_id}
* operationId: DeleteCustomersCustomerAddressesAddress
@@ -25,7 +27,8 @@ export default async (req, res) => {
try {
await customerService.removeAddress(id, address_id)
customer = await customerService.retrieve(id, {
relations: ["shipping_addresses"],
relations: defaultRelations,
select: defaultFields,
})
res.json({ customer })
@@ -1,3 +1,5 @@
import { defaultRelations, defaultFields } from "./"
/**
* @oas [get] /customers/{id}
* operationId: GetCustomersCustomer
@@ -22,7 +24,8 @@ export default async (req, res) => {
try {
const customerService = req.scope.resolve("customerService")
const customer = await customerService.retrieve(id, {
relations: ["shipping_addresses"],
relations: defaultRelations,
select: defaultFields,
})
res.json({ customer })
} catch (err) {
@@ -57,3 +57,39 @@ export default (app, container) => {
return app
}
export const defaultRelations = ["shipping_addresses"]
export const defaultFields = [
"id",
"email",
"first_name",
"last_name",
"billing_address_id",
"phone",
"has_account",
"created_at",
"updated_at",
"deleted_at",
"metadata",
]
export const allowedRelations = [
"shipping_addresses",
"billing_address",
"orders",
]
export const allowedFields = [
"id",
"email",
"first_name",
"last_name",
"billing_address_id",
"phone",
"has_account",
"created_at",
"updated_at",
"deleted_at",
"metadata",
]
@@ -1,4 +1,5 @@
import { Validator, MedusaError } from "medusa-core-utils"
import { defaultRelations, defaultFields } from "./"
/**
* @oas [post] /customers/{id}/addresses/{address_id}
@@ -50,7 +51,8 @@ export default async (req, res) => {
)
customer = await customerService.retrieve(id, {
relations: ["shipping_addresses"],
relations: defaultRelations,
select: defaultFields,
})
res.json({ customer })
@@ -1,4 +1,5 @@
import { Validator, MedusaError } from "medusa-core-utils"
import { defaultRelations, defaultFields } from "./"
/**
* @oas [post] /customers/{id}
@@ -24,6 +25,9 @@ import { Validator, MedusaError } from "medusa-core-utils"
* phone:
* description: "The Customer's phone number."
* type: string
* metadata:
* description: "Metadata about the customer."
* type: object
* tags:
* - Customer
* responses:
@@ -44,6 +48,7 @@ export default async (req, res) => {
last_name: Validator.string().optional(),
password: Validator.string().optional(),
phone: Validator.string().optional(),
metadata: Validator.object().optional(),
})
const { value, error } = schema.validate(req.body)
@@ -56,7 +61,8 @@ export default async (req, res) => {
let customer = await customerService.update(id, value)
customer = await customerService.retrieve(customer.id, {
relations: ["shipping_addresses"],
relations: defaultRelations,
select: defaultFields,
})
res.status(200).json({ customer })
@@ -4,28 +4,16 @@ export class gcRemoveUniqueOrder1624287602631 implements MigrationInterface {
name = "gcRemoveUniqueOrder1624287602631"
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "gift_card" DROP CONSTRAINT "FK_dfc1f02bb0552e79076aa58dbb0"`
)
await queryRunner.query(`ALTER TABLE "gift_card" DROP CONSTRAINT "FK_dfc1f02bb0552e79076aa58dbb0"`)
await queryRunner.query(`COMMENT ON COLUMN "gift_card"."order_id" IS NULL`)
await queryRunner.query(
`ALTER TABLE "gift_card" DROP CONSTRAINT "REL_dfc1f02bb0552e79076aa58dbb"`
)
await queryRunner.query(
`ALTER TABLE "gift_card" ADD CONSTRAINT "FK_dfc1f02bb0552e79076aa58dbb0" FOREIGN KEY ("order_id") REFERENCES "order"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`
)
await queryRunner.query(`ALTER TABLE "gift_card" DROP CONSTRAINT "REL_dfc1f02bb0552e79076aa58dbb"`)
await queryRunner.query(`ALTER TABLE "gift_card" ADD CONSTRAINT "FK_dfc1f02bb0552e79076aa58dbb0" FOREIGN KEY ("order_id") REFERENCES "order"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`)
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "gift_card" DROP CONSTRAINT "FK_dfc1f02bb0552e79076aa58dbb0"`
)
await queryRunner.query(
`ALTER TABLE "gift_card" ADD CONSTRAINT "REL_dfc1f02bb0552e79076aa58dbb" UNIQUE ("order_id")`
)
await queryRunner.query(`ALTER TABLE "gift_card" DROP CONSTRAINT "FK_dfc1f02bb0552e79076aa58dbb0"`)
await queryRunner.query(`ALTER TABLE "gift_card" ADD CONSTRAINT "REL_dfc1f02bb0552e79076aa58dbb" UNIQUE ("order_id")`)
await queryRunner.query(`COMMENT ON COLUMN "gift_card"."order_id" IS NULL`)
await queryRunner.query(
`ALTER TABLE "gift_card" ADD CONSTRAINT "FK_dfc1f02bb0552e79076aa58dbb0" FOREIGN KEY ("order_id") REFERENCES "order"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`
)
await queryRunner.query(`ALTER TABLE "gift_card" ADD CONSTRAINT "FK_dfc1f02bb0552e79076aa58dbb0" FOREIGN KEY ("order_id") REFERENCES "order"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`)
}
}
@@ -0,0 +1,42 @@
import {MigrationInterface, QueryRunner} from "typeorm";
export class softDeletingUniqueConstraints1624610325746 implements MigrationInterface {
name = 'softDeletingUniqueConstraints1624610325746'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DROP INDEX "IDX_6910923cb678fd6e99011a21cc"`);
await queryRunner.query(`DROP INDEX "IDX_db7355f7bd36c547c8a4f539e5"`);
await queryRunner.query(`DROP INDEX "IDX_087926f6fec32903be3c8eedfa"`);
await queryRunner.query(`DROP INDEX "IDX_f4dc2c0888b66d547c175f090e"`);
await queryRunner.query(`DROP INDEX "IDX_9db95c4b71f632fc93ecbc3d8b"`);
await queryRunner.query(`DROP INDEX "IDX_7124082c8846a06a857cca386c"`);
await queryRunner.query(`DROP INDEX "IDX_a0a3f124dc5b167622217fee02"`);
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_e08af711f3493df1e921c4c9ef" ON "product_collection" ("handle") WHERE deleted_at IS NOT NULL`);
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_77c4073c30ea7793f484750529" ON "product" ("handle") WHERE deleted_at IS NOT NULL`);
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_ae3e22c67d7c7a969a363533c0" ON "discount" ("code") WHERE deleted_at IS NOT NULL`);
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_0683952543d7d3f4fffc427034" ON "product_variant" ("sku") WHERE deleted_at IS NOT NULL`);
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_410649600ce31c10c4b667ca10" ON "product_variant" ("barcode") WHERE deleted_at IS NOT NULL`);
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_5248fda27b9f16ef818604bb6f" ON "product_variant" ("ean") WHERE deleted_at IS NOT NULL`);
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_832f86daf8103491d634a967da" ON "product_variant" ("upc") WHERE deleted_at IS NOT NULL`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DROP INDEX "IDX_ae3e22c67d7c7a969a363533c0"`);
await queryRunner.query(`DROP INDEX "IDX_77c4073c30ea7793f484750529"`);
await queryRunner.query(`DROP INDEX "IDX_e08af711f3493df1e921c4c9ef"`);
await queryRunner.query(`DROP INDEX "IDX_832f86daf8103491d634a967da"`);
await queryRunner.query(`DROP INDEX "IDX_5248fda27b9f16ef818604bb6f"`);
await queryRunner.query(`DROP INDEX "IDX_410649600ce31c10c4b667ca10"`);
await queryRunner.query(`DROP INDEX "IDX_0683952543d7d3f4fffc427034"`);
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_087926f6fec32903be3c8eedfa" ON "discount" ("code") `);
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_db7355f7bd36c547c8a4f539e5" ON "product" ("handle") `);
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_6910923cb678fd6e99011a21cc" ON "product_collection" ("handle") `);
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_a0a3f124dc5b167622217fee02" ON "product_variant" ("upc") `);
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_7124082c8846a06a857cca386c" ON "product_variant" ("ean") `);
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_9db95c4b71f632fc93ecbc3d8b" ON "product_variant" ("barcode") `);
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_f4dc2c0888b66d547c175f090e" ON "product_variant" ("sku") `);
}
}
+1 -1
View File
@@ -23,7 +23,7 @@ export class Discount {
@PrimaryColumn()
id: string
@Index({ unique: true })
@Index({ unique: true, where: "deleted_at IS NOT NULL" })
@Column()
code: string
@@ -23,7 +23,7 @@ export class ProductCollection {
@Column()
title: string
@Index({ unique: true })
@Index({ unique: true, where: "deleted_at IS NOT NULL" })
@Column({ nullable: true })
handle: string
@@ -50,19 +50,19 @@ export class ProductVariant {
prices: MoneyAmount[]
@Column({ nullable: true })
@Index({ unique: true })
@Index({ unique: true, where: "deleted_at IS NOT NULL" })
sku: string
@Index({ unique: true })
@Column({ nullable: true })
@Index({ unique: true, where: "deleted_at IS NOT NULL" })
barcode: string
@Index({ unique: true })
@Column({ nullable: true })
@Index({ unique: true, where: "deleted_at IS NOT NULL" })
ean: string
@Index({ unique: true })
@Column({ nullable: true })
@Index({ unique: true, where: "deleted_at IS NOT NULL" })
upc: string
@Column({ type: "int" })
+1 -1
View File
@@ -39,7 +39,7 @@ export class Product {
@Column({ nullable: true })
description: string
@Index({ unique: true })
@Index({ unique: true, where: "deleted_at IS NOT NULL" })
@Column({ nullable: true })
handle: string
@@ -135,8 +135,8 @@ describe("ProductCollectionService", () => {
it("successfully removes a product collection", async () => {
await productCollectionService.delete(IdMap.getId("bathrobe"))
expect(productCollectionRepository.remove).toHaveBeenCalledTimes(1)
expect(productCollectionRepository.remove).toHaveBeenCalledWith({
expect(productCollectionRepository.softRemove).toHaveBeenCalledTimes(1)
expect(productCollectionRepository.softRemove).toHaveBeenCalledWith({
id: IdMap.getId("bathrobe"),
})
})
+7
View File
@@ -318,6 +318,13 @@ class CustomerService extends BaseService {
const existing = await this.retrieveByEmail(email).catch(err => undefined)
if (existing && existing.has_account) {
throw new MedusaError(
MedusaError.Types.DUPLICATE_ERROR,
"A customer with the given email already has an account. Log in instead"
)
}
if (existing && password && !existing.has_account) {
const hashedPassword = await this.hashPassword_(password)
customer.password_hash = hashedPassword
@@ -129,7 +129,7 @@ class ProductCollectionService extends BaseService {
if (!collection) return Promise.resolve()
await productCollectionRepo.remove(collection)
await productCollectionRepo.softRemove(collection)
return Promise.resolve()
})