@labdigital/commercetools-mock 2.14.0 → 2.14.2

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 CHANGED
@@ -3190,6 +3190,46 @@ var CustomerRepository = class extends AbstractResourceRepository {
3190
3190
  changeEmail: (_context, resource, { email }) => {
3191
3191
  resource.email = email;
3192
3192
  },
3193
+ setFirstName: (_context, resource, { firstName }) => {
3194
+ resource.firstName = firstName;
3195
+ },
3196
+ setLastName: (_context, resource, { lastName }) => {
3197
+ resource.lastName = lastName;
3198
+ },
3199
+ setCompanyName: (_context, resource, { companyName }) => {
3200
+ resource.companyName = companyName;
3201
+ },
3202
+ setVatId: (_context, resource, { vatId }) => {
3203
+ resource.vatId = vatId;
3204
+ },
3205
+ changeAddress: (context, resource, { addressId, addressKey, address }) => {
3206
+ const oldAddressIndex = resource.addresses.findIndex((a) => {
3207
+ if (a.id != void 0 && addressId != void 0 && a.id === addressId) {
3208
+ return true;
3209
+ }
3210
+ return a.key != void 0 && addressKey != void 0 && a.key === addressKey;
3211
+ });
3212
+ if (oldAddressIndex === -1) {
3213
+ throw new CommercetoolsError(
3214
+ {
3215
+ code: "InvalidInput",
3216
+ message: `Address with id '${addressId}' or key '${addressKey}' not found.`
3217
+ },
3218
+ 400
3219
+ );
3220
+ }
3221
+ const newAddress = createAddress(
3222
+ address,
3223
+ context.projectKey,
3224
+ this._storage
3225
+ );
3226
+ if (newAddress) {
3227
+ resource.addresses[oldAddressIndex] = {
3228
+ id: addressId,
3229
+ ...newAddress
3230
+ };
3231
+ }
3232
+ },
3193
3233
  setAuthenticationMode: (_context, resource, { authMode, password }) => {
3194
3234
  if (resource.authenticationMode === authMode) {
3195
3235
  throw new CommercetoolsError(
@@ -6867,6 +6907,7 @@ var MyCustomerService = class extends AbstractService {
6867
6907
  router.delete("", this.deleteMe.bind(this));
6868
6908
  router.post("/signup", this.signUp.bind(this));
6869
6909
  router.post("/login", this.signIn.bind(this));
6910
+ router.post("/password", this.changePassword.bind(this));
6870
6911
  parent.use(`/${basePath}`, router);
6871
6912
  }
6872
6913
  getMe(request, response) {
@@ -6907,6 +6948,30 @@ var MyCustomerService = class extends AbstractService {
6907
6948
  const result = this._expandWithId(request, resource.id);
6908
6949
  return response.status(this.createStatusCode).send({ customer: result });
6909
6950
  }
6951
+ changePassword(request, response) {
6952
+ const { currentPassword, newPassword } = request.body;
6953
+ const encodedPassword = hashPassword(currentPassword);
6954
+ const result = this.repository.query(getRepositoryContext(request), {
6955
+ where: [`password = "${encodedPassword}"`]
6956
+ });
6957
+ if (result.count === 0) {
6958
+ return response.status(404).send({
6959
+ message: "Account with the given credentials not found.",
6960
+ errors: [
6961
+ {
6962
+ code: "InvalidCurrentPassword",
6963
+ message: "Account with the given credentials not found."
6964
+ }
6965
+ ]
6966
+ });
6967
+ }
6968
+ const newCustomer = {
6969
+ ...result.results[0],
6970
+ password: hashPassword(newPassword)
6971
+ };
6972
+ this.repository.saveNew(getRepositoryContext(request), newCustomer);
6973
+ return response.status(200).send(newCustomer);
6974
+ }
6910
6975
  signIn(request, response) {
6911
6976
  const { email, password } = request.body;
6912
6977
  const encodedPassword = hashPassword(password);