@labdigital/commercetools-mock 2.13.0 → 2.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +112 -37
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +16 -4
- package/dist/index.d.ts +16 -4
- package/dist/index.js +112 -37
- package/dist/index.js.map +1 -1
- package/package.json +31 -31
- package/src/repositories/cart.ts +2 -2
- package/src/repositories/customer.ts +72 -0
- package/src/repositories/order.ts +1 -1
- package/src/repositories/payment.ts +92 -47
- package/src/repositories/product.ts +5 -5
- package/src/repositories/review.ts +2 -2
- package/src/repositories/shopping-list.ts +1 -1
- package/src/services/customer.test.ts +154 -0
- package/src/services/customer.ts +1 -1
- package/src/services/my-customer.test.ts +32 -2
- package/src/services/my-customer.ts +32 -1
|
@@ -3,7 +3,7 @@ import { CustomerRepository } from '../repositories/customer.js'
|
|
|
3
3
|
import { getRepositoryContext } from '../repositories/helpers.js'
|
|
4
4
|
import AbstractService from './abstract.js'
|
|
5
5
|
import { hashPassword } from '../lib/password.js'
|
|
6
|
-
import { Update } from '@commercetools/platform-sdk'
|
|
6
|
+
import { Customer, Update } from '@commercetools/platform-sdk'
|
|
7
7
|
|
|
8
8
|
export class MyCustomerService extends AbstractService {
|
|
9
9
|
public repository: CustomerRepository
|
|
@@ -31,6 +31,7 @@ export class MyCustomerService extends AbstractService {
|
|
|
31
31
|
router.post('/signup', this.signUp.bind(this))
|
|
32
32
|
|
|
33
33
|
router.post('/login', this.signIn.bind(this))
|
|
34
|
+
router.post('/password', this.changePassword.bind(this))
|
|
34
35
|
|
|
35
36
|
parent.use(`/${basePath}`, router)
|
|
36
37
|
}
|
|
@@ -79,6 +80,36 @@ export class MyCustomerService extends AbstractService {
|
|
|
79
80
|
return response.status(this.createStatusCode).send({ customer: result })
|
|
80
81
|
}
|
|
81
82
|
|
|
83
|
+
changePassword(request: Request, response: Response) {
|
|
84
|
+
const { currentPassword, newPassword } = request.body
|
|
85
|
+
const encodedPassword = hashPassword(currentPassword)
|
|
86
|
+
|
|
87
|
+
const result = this.repository.query(getRepositoryContext(request), {
|
|
88
|
+
where: [`password = "${encodedPassword}"`],
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
if (result.count === 0) {
|
|
92
|
+
return response.status(404).send({
|
|
93
|
+
message: 'Account with the given credentials not found.',
|
|
94
|
+
errors: [
|
|
95
|
+
{
|
|
96
|
+
code: 'InvalidCredentials',
|
|
97
|
+
message: 'Account with the given credentials not found.',
|
|
98
|
+
},
|
|
99
|
+
],
|
|
100
|
+
})
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const newCustomer: Customer = {
|
|
104
|
+
...result.results[0],
|
|
105
|
+
password: hashPassword(newPassword),
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
this.repository.saveNew(getRepositoryContext(request), newCustomer)
|
|
109
|
+
|
|
110
|
+
return response.status(200).send(newCustomer)
|
|
111
|
+
}
|
|
112
|
+
|
|
82
113
|
signIn(request: Request, response: Response) {
|
|
83
114
|
const { email, password } = request.body
|
|
84
115
|
const encodedPassword = hashPassword(password)
|