@labdigital/commercetools-mock 0.5.20 → 0.5.21

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.
@@ -9,4 +9,5 @@ export declare class MyCustomerService extends AbstractService {
9
9
  registerRoutes(parent: Router): void;
10
10
  getMe(request: Request, response: Response): Response<any, Record<string, any>>;
11
11
  signUp(request: Request, response: Response): Response<any, Record<string, any>>;
12
+ signIn(request: Request, response: Response): Response<any, Record<string, any>>;
12
13
  }
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.5.20",
2
+ "version": "0.5.21",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
package/src/.env ADDED
File without changes
@@ -12,6 +12,7 @@ export class CustomerRepository extends AbstractResourceRepository {
12
12
  getTypeId(): ReferenceTypeId {
13
13
  return 'customer'
14
14
  }
15
+
15
16
  create(projectKey: string, draft: CustomerDraft): Customer {
16
17
  const resource: Customer = {
17
18
  ...getBaseResourceProperties(),
@@ -23,6 +24,7 @@ export class CustomerRepository extends AbstractResourceRepository {
23
24
  this.save(projectKey, resource)
24
25
  return resource
25
26
  }
27
+
26
28
  getMe(projectKey: string): Customer | undefined {
27
29
  const results = this._storage.query(projectKey, this.getTypeId(), {}) // grab the first customer you can find
28
30
  if (results.count > 0) {
@@ -26,6 +26,8 @@ export class MyCustomerService extends AbstractService {
26
26
 
27
27
  router.post('/signup', this.signUp.bind(this))
28
28
 
29
+ router.post('/login', this.signIn.bind(this))
30
+
29
31
  parent.use(`/${basePath}`, router)
30
32
  }
31
33
 
@@ -43,4 +45,27 @@ export class MyCustomerService extends AbstractService {
43
45
  const result = this._expandWithId(request, resource.id)
44
46
  return response.status(this.createStatusCode).send({ customer: result })
45
47
  }
48
+
49
+ signIn(request: Request, response: Response) {
50
+ const { email, password } = request.body
51
+ const encodedPassword = Buffer.from(password).toString('base64')
52
+
53
+ const result = this.repository.query(request.params.projectKey, {
54
+ where: [`email = "${email}"`, `password = "${encodedPassword}"`],
55
+ })
56
+
57
+ if (result.count === 0) {
58
+ return response.status(400).send({
59
+ message: 'Account with the given credentials not found.',
60
+ errors: [
61
+ {
62
+ code: 'InvalidCredentials',
63
+ message: 'Account with the given credentials not found.',
64
+ },
65
+ ],
66
+ })
67
+ }
68
+
69
+ return response.status(200).send({ customer: result.results[0] })
70
+ }
46
71
  }