|
@@ -1,11 +1,10 @@
|
|
|
import { Request, Response } from 'express';
|
|
import { Request, Response } from 'express';
|
|
|
|
|
|
|
|
import { LoginMutationArgs, LoginResult } from '../../../../../shared/generated-types';
|
|
import { LoginMutationArgs, LoginResult } from '../../../../../shared/generated-types';
|
|
|
|
|
+import { InternalServerError } from '../../../common/error/errors';
|
|
|
import { ConfigService } from '../../../config/config.service';
|
|
import { ConfigService } from '../../../config/config.service';
|
|
|
import { User } from '../../../entity/user/user.entity';
|
|
import { User } from '../../../entity/user/user.entity';
|
|
|
import { AuthService } from '../../../service/services/auth.service';
|
|
import { AuthService } from '../../../service/services/auth.service';
|
|
|
-import { ChannelService } from '../../../service/services/channel.service';
|
|
|
|
|
-import { CustomerService } from '../../../service/services/customer.service';
|
|
|
|
|
import { UserService } from '../../../service/services/user.service';
|
|
import { UserService } from '../../../service/services/user.service';
|
|
|
import { extractAuthToken } from '../../common/extract-auth-token';
|
|
import { extractAuthToken } from '../../common/extract-auth-token';
|
|
|
import { RequestContext } from '../../common/request-context';
|
|
import { RequestContext } from '../../common/request-context';
|
|
@@ -78,6 +77,25 @@ export class BaseAuthResolver {
|
|
|
};
|
|
};
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Updates the password of an existing User.
|
|
|
|
|
+ */
|
|
|
|
|
+ protected async updatePassword(
|
|
|
|
|
+ ctx: RequestContext,
|
|
|
|
|
+ currentPassword: string,
|
|
|
|
|
+ newPassword: string,
|
|
|
|
|
+ ): Promise<boolean> {
|
|
|
|
|
+ const { activeUserId } = ctx;
|
|
|
|
|
+ if (!activeUserId) {
|
|
|
|
|
+ throw new InternalServerError(`error.no-active-user-id`);
|
|
|
|
|
+ }
|
|
|
|
|
+ const user = await this.userService.getUserById(activeUserId);
|
|
|
|
|
+ if (!user) {
|
|
|
|
|
+ throw new InternalServerError(`error.no-active-user-id`);
|
|
|
|
|
+ }
|
|
|
|
|
+ return this.userService.updatePassword(user, currentPassword, newPassword);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* Exposes a subset of the User properties which we want to expose to the public API.
|
|
* Exposes a subset of the User properties which we want to expose to the public API.
|
|
|
*/
|
|
*/
|