Merge branch 'develop' into feat/rma-shipping-options
This commit is contained in:
@@ -221,5 +221,47 @@ describe("/store/customers", () => {
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("unsets customer billing address", async () => {
|
||||||
|
const api = useApi()
|
||||||
|
|
||||||
|
const authResponse = await api.post("/store/auth", {
|
||||||
|
email: "john@deere.com",
|
||||||
|
password: "test",
|
||||||
|
})
|
||||||
|
|
||||||
|
const customerId = authResponse.data.customer.id
|
||||||
|
const [authCookie] = authResponse.headers["set-cookie"][0].split(";")
|
||||||
|
|
||||||
|
const check = await api.post(
|
||||||
|
`/store/customers/me`,
|
||||||
|
{
|
||||||
|
billing_address: "addr_test",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
Cookie: authCookie,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(check.status).toEqual(200)
|
||||||
|
expect(check.data.customer.billing_address_id).toEqual("addr_test")
|
||||||
|
|
||||||
|
const response = await api.post(
|
||||||
|
`/store/customers/me`,
|
||||||
|
{
|
||||||
|
billing_address: null,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
Cookie: authCookie,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(response.status).toEqual(200)
|
||||||
|
expect(response.data.customer.billing_address_id).toEqual(null)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -65,6 +65,12 @@ describe("/store/variants", () => {
|
|||||||
updated_at: expect.any(String),
|
updated_at: expect.any(String),
|
||||||
weight: null,
|
weight: null,
|
||||||
width: null,
|
width: null,
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
created_at: expect.any(String),
|
||||||
|
updated_at: expect.any(String),
|
||||||
|
},
|
||||||
|
],
|
||||||
prices: [
|
prices: [
|
||||||
{
|
{
|
||||||
created_at: expect.any(String),
|
created_at: expect.any(String),
|
||||||
@@ -116,6 +122,12 @@ describe("/store/variants", () => {
|
|||||||
updated_at: expect.any(String),
|
updated_at: expect.any(String),
|
||||||
weight: null,
|
weight: null,
|
||||||
width: null,
|
width: null,
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
created_at: expect.any(String),
|
||||||
|
updated_at: expect.any(String),
|
||||||
|
},
|
||||||
|
],
|
||||||
prices: [
|
prices: [
|
||||||
{
|
{
|
||||||
created_at: expect.any(String),
|
created_at: expect.any(String),
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ export default async (req, res) => {
|
|||||||
const id = req.user.customer_id
|
const id = req.user.customer_id
|
||||||
|
|
||||||
const schema = Validator.object().keys({
|
const schema = Validator.object().keys({
|
||||||
billing_address: Validator.address().optional(),
|
billing_address: Validator.address().optional().allow(null),
|
||||||
first_name: Validator.string().optional(),
|
first_name: Validator.string().optional(),
|
||||||
last_name: Validator.string().optional(),
|
last_name: Validator.string().optional(),
|
||||||
password: Validator.string().optional(),
|
password: Validator.string().optional(),
|
||||||
@@ -66,9 +66,9 @@ export default async (req, res) => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const customerService = req.scope.resolve("customerService")
|
const customerService = req.scope.resolve("customerService")
|
||||||
let customer = await customerService.update(id, value)
|
await customerService.update(id, value)
|
||||||
|
|
||||||
customer = await customerService.retrieve(customer.id, {
|
const customer = await customerService.retrieve(id, {
|
||||||
relations: defaultRelations,
|
relations: defaultRelations,
|
||||||
select: defaultFields,
|
select: defaultFields,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -224,7 +224,6 @@ class CustomerService extends BaseService {
|
|||||||
const query = this.buildQuery_({ id: validatedId }, config)
|
const query = this.buildQuery_({ id: validatedId }, config)
|
||||||
|
|
||||||
const customer = await customerRepo.findOne(query)
|
const customer = await customerRepo.findOne(query)
|
||||||
|
|
||||||
if (!customer) {
|
if (!customer) {
|
||||||
throw new MedusaError(
|
throw new MedusaError(
|
||||||
MedusaError.Types.NOT_FOUND,
|
MedusaError.Types.NOT_FOUND,
|
||||||
@@ -286,7 +285,7 @@ class CustomerService extends BaseService {
|
|||||||
/**
|
/**
|
||||||
* Hashes a password
|
* Hashes a password
|
||||||
* @param {string} password - the value to hash
|
* @param {string} password - the value to hash
|
||||||
* @return {string} hashed password
|
* @return {Promise<string>} hashed password
|
||||||
*/
|
*/
|
||||||
async hashPassword_(password) {
|
async hashPassword_(password) {
|
||||||
const buf = await Scrypt.kdf(password, { logN: 1, r: 1, p: 1 })
|
const buf = await Scrypt.kdf(password, { logN: 1, r: 1, p: 1 })
|
||||||
@@ -371,7 +370,14 @@ class CustomerService extends BaseService {
|
|||||||
|
|
||||||
const customer = await this.retrieve(customerId)
|
const customer = await this.retrieve(customerId)
|
||||||
|
|
||||||
const { email, password, metadata, ...rest } = update
|
const {
|
||||||
|
email,
|
||||||
|
password,
|
||||||
|
metadata,
|
||||||
|
billing_address,
|
||||||
|
billing_address_id,
|
||||||
|
...rest
|
||||||
|
} = update
|
||||||
|
|
||||||
if (metadata) {
|
if (metadata) {
|
||||||
customer.metadata = this.setMetadata_(customer, metadata)
|
customer.metadata = this.setMetadata_(customer, metadata)
|
||||||
@@ -382,7 +388,7 @@ class CustomerService extends BaseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ("billing_address_id" in update || "billing_address" in update) {
|
if ("billing_address_id" in update || "billing_address" in update) {
|
||||||
const address = update.billing_address_id || update.billing_address
|
const address = billing_address_id || billing_address
|
||||||
await this.updateBillingAddress_(customer, address, addrRepo)
|
await this.updateBillingAddress_(customer, address, addrRepo)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -411,6 +417,11 @@ class CustomerService extends BaseService {
|
|||||||
* @return {Promise} the result of the update operation
|
* @return {Promise} the result of the update operation
|
||||||
*/
|
*/
|
||||||
async updateBillingAddress_(customer, addressOrId, addrRepo) {
|
async updateBillingAddress_(customer, addressOrId, addrRepo) {
|
||||||
|
if (addressOrId === null) {
|
||||||
|
customer.billing_address_id = null
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if (typeof addressOrId === `string`) {
|
if (typeof addressOrId === `string`) {
|
||||||
addressOrId = await addrRepo.findOne({
|
addressOrId = await addrRepo.findOne({
|
||||||
where: { id: addressOrId },
|
where: { id: addressOrId },
|
||||||
@@ -421,7 +432,6 @@ class CustomerService extends BaseService {
|
|||||||
|
|
||||||
if (addressOrId.id) {
|
if (addressOrId.id) {
|
||||||
customer.billing_address_id = addressOrId.id
|
customer.billing_address_id = addressOrId.id
|
||||||
customer.billing_address = addressOrId
|
|
||||||
} else {
|
} else {
|
||||||
if (customer.billing_address_id) {
|
if (customer.billing_address_id) {
|
||||||
const addr = await addrRepo.findOne({
|
const addr = await addrRepo.findOne({
|
||||||
|
|||||||
Reference in New Issue
Block a user