This commit is contained in:
2025-07-16 16:25:16 +09:00
parent 11af12a806
commit 8135650344
34 changed files with 301 additions and 41 deletions

View File

@@ -23,10 +23,10 @@ let AuthController = class AuthController {
this.authService = authService;
}
async signup(dto) {
return this.authService.signup(dto);
return await this.authService.signup(dto);
}
async login(dto) {
return this.authService.login(dto);
return await this.authService.login(dto);
}
};
exports.AuthController = AuthController;

View File

@@ -1 +1 @@
{"version":3,"file":"auth.controller.js","sourceRoot":"","sources":["../../src/auth/auth.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAwD;AACxD,iDAA6C;AAC7C,kEAA8D;AAC9D,yDAA2D;AAGpD,IAAM,cAAc,GAApB,MAAM,cAAc;IACM;IAA7B,YAA6B,WAAwB;QAAxB,gBAAW,GAAX,WAAW,CAAa;IAAG,CAAC;IAGnD,AAAN,KAAK,CAAC,MAAM,CAAS,GAAkB;QACnC,OAAO,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACxC,CAAC;IAGK,AAAN,KAAK,CAAC,KAAK,CAAS,GAAiB;QACjC,OAAO,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACvC,CAAC;CACJ,CAAA;AAZY,wCAAc;AAIjB;IADL,IAAA,aAAI,EAAC,QAAQ,CAAC;IACD,WAAA,IAAA,aAAI,GAAE,CAAA;;qCAAM,+BAAa;;4CAEtC;AAGK;IADL,IAAA,aAAI,EAAC,OAAO,CAAC;IACD,WAAA,IAAA,aAAI,GAAE,CAAA;;qCAAM,6BAAY;;2CAEpC;yBAXQ,cAAc;IAD1B,IAAA,mBAAU,EAAC,MAAM,CAAC;qCAE2B,0BAAW;GAD5C,cAAc,CAY1B"}
{"version":3,"file":"auth.controller.js","sourceRoot":"","sources":["../../src/auth/auth.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAwD;AACxD,iDAA6C;AAC7C,kEAA8D;AAC9D,yDAA2D;AAGpD,IAAM,cAAc,GAApB,MAAM,cAAc;IACM;IAA7B,YAA6B,WAAwB;QAAxB,gBAAW,GAAX,WAAW,CAAa;IAAG,CAAC;IAGnD,AAAN,KAAK,CAAC,MAAM,CAAS,GAAkB;QACnC,OAAO,MAAM,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAC9C,CAAC;IAGK,AAAN,KAAK,CAAC,KAAK,CAAS,GAAiB;QACjC,OAAO,MAAM,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC7C,CAAC;CACJ,CAAA;AAZY,wCAAc;AAIjB;IADL,IAAA,aAAI,EAAC,QAAQ,CAAC;IACD,WAAA,IAAA,aAAI,GAAE,CAAA;;qCAAM,+BAAa;;4CAEtC;AAGK;IADL,IAAA,aAAI,EAAC,OAAO,CAAC;IACD,WAAA,IAAA,aAAI,GAAE,CAAA;;qCAAM,6BAAY;;2CAEpC;yBAXQ,cAAc;IAD1B,IAAA,mBAAU,EAAC,MAAM,CAAC;qCAE2B,0BAAW;GAD5C,cAAc,CAY1B"}

View File

@@ -14,6 +14,7 @@ const users_module_1 = require("../users/users.module");
const jwt_1 = require("@nestjs/jwt");
const config_1 = require("@nestjs/config");
const passport_1 = require("@nestjs/passport");
const jwt_stratedy_1 = require("./jwt.stratedy");
let AuthModule = class AuthModule {
};
exports.AuthModule = AuthModule;
@@ -31,10 +32,10 @@ exports.AuthModule = AuthModule = __decorate([
signOptions: {
expiresIn: configService.get('JWT_EXPIRES_IN') || '60s',
},
})
}),
})
],
providers: [auth_service_1.AuthService],
providers: [auth_service_1.AuthService, jwt_stratedy_1.JwtStrategy],
controllers: [auth_controller_1.AuthController]
})
], AuthModule);

View File

@@ -1 +1 @@
{"version":3,"file":"auth.module.js","sourceRoot":"","sources":["../../src/auth/auth.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,iDAA6C;AAC7C,uDAAmD;AACnD,wDAAqD;AACrD,qCAAw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WAAW,EAAE;wBACX,SAAS,EAAE,aAAa,CAAC,GAAG,CAAS,gBAAgB,CAAC,IAAI,KAAK;qBAChE;iBACF,CAAC;aACH,CAAC;SACH;QACD,SAAS,EAAE,CAAC,0BAAW,EAAE,0BAAW,CAAC;QACrC,WAAW,EAAE,CAAC,gCAAc,CAAC;KAC9B,CAAC;GACW,UAAU,CAAG"}

View File

@@ -30,30 +30,18 @@ let AuthService = class AuthService {
return null;
}
async login(dto) {
try {
const user = await this.userService.findByName(dto.name);
if (!user)
throw new common_1.UnauthorizedException('Login failed');
const passwordCheck = await bcrypt.compare(dto.password, user.password);
if (!passwordCheck)
throw new common_1.UnauthorizedException('Login failed');
const payload = { username: user.name, sub: user.id };
return { access_token: this.jwtService.sign(payload) };
}
catch (error) {
if (error instanceof common_1.UnauthorizedException)
throw error;
throw new common_1.InternalServerErrorException('Login failed (Internal)');
}
const user = await this.userService.findByName(dto.name);
if (!user)
throw new common_1.UnauthorizedException('Login failed');
const passwordCheck = await bcrypt.compare(dto.password, user.password);
if (!passwordCheck)
throw new common_1.UnauthorizedException('Login failed');
const payload = { username: user.name, sub: user.id };
return { access_token: this.jwtService.sign(payload) };
}
async signup(dto) {
try {
const hashed = await bcrypt.hash(dto.password, 10);
return this.userService.create({ ...dto, password: hashed });
}
catch (error) {
throw new common_1.BadRequestException('Signup failed');
}
const hashed = await bcrypt.hash(dto.password, 10);
return this.userService.create({ ...dto, password: hashed });
}
};
exports.AuthService = AuthService;

View File

@@ -1 +1 @@
{"version":3,"file":"auth.service.js","sourceRoot":"","sources":["../../src/auth/auth.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAsH;AACtH,qCAAyC;AACzC,0DAAuD;AACvD,iCAAgC;AAKzB,IAAM,WAAW,GAAjB,MAAM,WAAW;IACA;IAAmC;IAAvD,YAAoB,WAAyB,EAAU,UAAsB;QAAzD,gBAAW,GAAX,WAAW,CAAc;QAAU,eAAU,GAAV,UAAU,CAAY;IAAG,CAAC;I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AAC,CAAC;QACrD,IAAI,CAAC,IAAI;YAAE,MAAM,IAAI,8BAAqB,CAAC,cAAc,CAAC,CAAC;QAE3D,MAAM,aAAa,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;QACxE,IAAI,CAAC,aAAa;YAAE,MAAM,IAAI,8BAAqB,CAAC,cAAc,CAAC,CAAC;QAEpE,MAAM,OAAO,GAAG,EAAE,QAAQ,EAAE,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC;QACtD,OAAO,EAAE,YAAY,EAAE,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;IAC/D,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,GAAkB;QAC3B,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;QAC/C,OAAO,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,GAAG,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;IACrE,CAAC;CACJ,CAAA;AA7BY,kCAAW;sBAAX,WAAW;IADvB,IAAA,mBAAU,GAAE;qCAEwB,4BAAY,EAAsB,gBAAU;GADpE,WAAW,CA6BvB"}

4
backend/dist/auth/jwt-auth.guard.d.ts vendored Executable file
View File

@@ -0,0 +1,4 @@
declare const JwtAuthGuard_base: import("@nestjs/passport").Type<import("@nestjs/passport").IAuthGuard>;
export declare class JwtAuthGuard extends JwtAuthGuard_base {
}
export {};

18
backend/dist/auth/jwt-auth.guard.js vendored Executable file
View File

@@ -0,0 +1,18 @@
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.JwtAuthGuard = void 0;
const common_1 = require("@nestjs/common");
const passport_1 = require("@nestjs/passport");
let JwtAuthGuard = class JwtAuthGuard extends (0, passport_1.AuthGuard)('jwt') {
};
exports.JwtAuthGuard = JwtAuthGuard;
exports.JwtAuthGuard = JwtAuthGuard = __decorate([
(0, common_1.Injectable)()
], JwtAuthGuard);
//# sourceMappingURL=jwt-auth.guard.js.map

1
backend/dist/auth/jwt-auth.guard.js.map vendored Executable file
View File

@@ -0,0 +1 @@
{"version":3,"file":"jwt-auth.guard.js","sourceRoot":"","sources":["../../src/auth/jwt-auth.guard.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA4C;AAC5C,+CAA6C;AAGtC,IAAM,YAAY,GAAlB,MAAM,YAAa,SAAQ,IAAA,oBAAS,EAAC,KAAK,CAAC;CAAG,CAAA;AAAxC,oCAAY;uBAAZ,YAAY;IADxB,IAAA,mBAAU,GAAE;GACA,YAAY,CAA4B"}

10
backend/dist/auth/jwt.stratedy.d.ts vendored Executable file
View File

@@ -0,0 +1,10 @@
import { ConfigService } from '@nestjs/config';
declare const JwtStrategy_base: new (...args: any) => any;
export declare class JwtStrategy extends JwtStrategy_base {
constructor(config: ConfigService);
validate(payload: any): Promise<{
userId: any;
username: any;
}>;
}
export {};

34
backend/dist/auth/jwt.stratedy.js vendored Executable file
View File

@@ -0,0 +1,34 @@
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.JwtStrategy = void 0;
const common_1 = require("@nestjs/common");
const passport_1 = require("@nestjs/passport");
const passport_jwt_1 = require("passport-jwt");
const config_1 = require("@nestjs/config");
let JwtStrategy = class JwtStrategy extends (0, passport_1.PassportStrategy)(passport_jwt_1.Strategy) {
constructor(config) {
super({
jwtFromRequest: passport_jwt_1.ExtractJwt.fromAuthHeaderAsBearerToken(),
ignoreExpiration: false,
secretOrKey: config.get('JWT_SECRET'),
});
}
async validate(payload) {
return { userId: payload.sub, username: payload.username };
}
};
exports.JwtStrategy = JwtStrategy;
exports.JwtStrategy = JwtStrategy = __decorate([
(0, common_1.Injectable)(),
__metadata("design:paramtypes", [config_1.ConfigService])
], JwtStrategy);
//# sourceMappingURL=jwt.stratedy.js.map

1
backend/dist/auth/jwt.stratedy.js.map vendored Executable file
View File

@@ -0,0 +1 @@
{"version":3,"file":"jwt.stratedy.js","sourceRoot":"","sources":["../../src/auth/jwt.stratedy.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,+CAAoD;AACpD,+CAAoD;AACpD,2CAA+C;AAGxC,IAAM,WAAW,GAAjB,MAAM,WAAY,SAAQ,IAAA,2BAAgB,EAAC,uBAAQ,CAAC;IACzD,YAAY,MAAqB;QAC/B,KAAK,CAAC;YACJ,cAAc,EAAE,yBAAU,CAAC,2BAA2B,EAAE;YACxD,gBAAgB,EAAE,KAAK;YACvB,WAAW,EAAE,MAAM,CAAC,GAAG,CAAS,YAAY,CAAC;SAC9C,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,OAAY;QACzB,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,GAAG,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAC;IAC7D,CAAC;CACF,CAAA;AAZY,kCAAW;sBAAX,WAAW;IADvB,IAAA,mBAAU,GAAE;qCAES,sBAAa;GADtB,WAAW,CAYvB"}

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,4 @@
export declare class ChangePasswordDto {
readonly currentPassword: string;
readonly newPassword: string;
}

28
backend/dist/users/dto/change-password.dto.js vendored Executable file
View File

@@ -0,0 +1,28 @@
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ChangePasswordDto = void 0;
const class_validator_1 = require("class-validator");
class ChangePasswordDto {
currentPassword;
newPassword;
}
exports.ChangePasswordDto = ChangePasswordDto;
__decorate([
(0, class_validator_1.IsString)(),
__metadata("design:type", String)
], ChangePasswordDto.prototype, "currentPassword", void 0);
__decorate([
(0, class_validator_1.IsString)(),
(0, class_validator_1.MinLength)(4),
__metadata("design:type", String)
], ChangePasswordDto.prototype, "newPassword", void 0);
//# sourceMappingURL=change-password.dto.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"change-password.dto.js","sourceRoot":"","sources":["../../../src/users/dto/change-password.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAA2E;AAE3E,MAAa,iBAAiB;IAEjB,eAAe,CAAS;IAIxB,WAAW,CAAS;CAChC;AAPD,8CAOC;AALY;IADR,IAAA,0BAAQ,GAAE;;0DACsB;AAIxB;IAFR,IAAA,0BAAQ,GAAE;IACV,IAAA,2BAAS,EAAC,CAAC,CAAC;;sDACgB"}

7
backend/dist/users/users.controller.d.ts vendored Executable file
View File

@@ -0,0 +1,7 @@
import { UsersService } from './users.service';
import { ChangePasswordDto } from './dto/change-password.dto';
export declare class UsersController {
private readonly userService;
constructor(userService: UsersService);
changePassword(req: any, dto: ChangePasswordDto): Promise<void>;
}

42
backend/dist/users/users.controller.js vendored Executable file
View File

@@ -0,0 +1,42 @@
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.UsersController = void 0;
const common_1 = require("@nestjs/common");
const users_service_1 = require("./users.service");
const change_password_dto_1 = require("./dto/change-password.dto");
let UsersController = class UsersController {
userService;
constructor(userService) {
this.userService = userService;
}
async changePassword(req, dto) {
console.log("dd");
return await this.userService.changePassword(req.user.userId, dto);
}
};
exports.UsersController = UsersController;
__decorate([
(0, common_1.Patch)('password'),
__param(0, (0, common_1.Request)()),
__param(1, (0, common_1.Body)()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object, change_password_dto_1.ChangePasswordDto]),
__metadata("design:returntype", Promise)
], UsersController.prototype, "changePassword", null);
exports.UsersController = UsersController = __decorate([
(0, common_1.Controller)('users'),
__metadata("design:paramtypes", [users_service_1.UsersService])
], UsersController);
//# sourceMappingURL=users.controller.js.map

1
backend/dist/users/users.controller.js.map vendored Executable file
View File

@@ -0,0 +1 @@
{"version":3,"file":"users.controller.js","sourceRoot":"","sources":["../../src/users/users.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAkE;AAClE,mDAA+C;AAC/C,mEAA8D;AAGvD,IAAM,eAAe,GAArB,MAAM,eAAe;IACK;IAA7B,YAA6B,WAAyB;QAAzB,gBAAW,GAAX,WAAW,CAAc;IAAG,CAAC;IAGpD,AAAN,KAAK,CAAC,cAAc,CAAY,GAAG,EAAU,GAAsB;QAC/D,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAClB,OAAO,MAAM,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACvE,CAAC;CACJ,CAAA;AARY,0CAAe;AAIlB;IADL,IAAA,cAAK,EAAC,UAAU,CAAC;IACI,WAAA,IAAA,gBAAO,GAAE,CAAA;IAAO,WAAA,IAAA,aAAI,GAAE,CAAA;;6CAAM,uCAAiB;;qDAGlE;0BAPQ,eAAe;IAD3B,IAAA,mBAAU,EAAC,OAAO,CAAC;qCAE0B,4BAAY;GAD7C,eAAe,CAQ3B"}

View File

@@ -11,6 +11,7 @@ const common_1 = require("@nestjs/common");
const users_service_1 = require("./users.service");
const typeorm_1 = require("@nestjs/typeorm");
const user_entity_1 = require("./user.entity");
const users_controller_1 = require("./users.controller");
let UsersModule = class UsersModule {
};
exports.UsersModule = UsersModule;
@@ -18,7 +19,7 @@ exports.UsersModule = UsersModule = __decorate([
(0, common_1.Module)({
imports: [typeorm_1.TypeOrmModule.forFeature([user_entity_1.User])],
providers: [users_service_1.UsersService],
controllers: [],
controllers: [users_controller_1.UsersController],
exports: [users_service_1.UsersService]
})
], UsersModule);

View File

@@ -1 +1 @@
{"version":3,"file":"users.module.js","sourceRoot":"","sources":["../../src/users/users.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,mDAA+C;AAC/C,6CAAgD;AAChD,+CAAqC;AAQ9B,IAAM,WAAW,GAAjB,MAAM,WAAW;CAAG,CAAA;AAAd,kCAAW;sBAAX,WAAW;IANvB,IAAA,eAAM,EAAC;QACN,OAAO,EAAE,CAAC,uBAAa,CAAC,UAAU,CAAC,CAAC,kBAAI,CAAC,CAAC,CAAC;QAC3C,SAAS,EAAE,CAAC,4BAAY,CAAC;QACzB,WAAW,EAAE,EAAE;QACf,OAAO,EAAE,CAAC,4BAAY,CAAC;KACxB,CAAC;GACW,WAAW,CAAG"}
{"version":3,"file":"users.module.js","sourceRoot":"","sources":["../../src/users/users.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,mDAA+C;AAC/C,6CAAgD;AAChD,+CAAqC;AACrC,yDAAqD;AAQ9C,IAAM,WAAW,GAAjB,MAAM,WAAW;CAAG,CAAA;AAAd,kCAAW;sBAAX,WAAW;IANvB,IAAA,eAAM,EAAC;QACN,OAAO,EAAE,CAAC,uBAAa,CAAC,UAAU,CAAC,CAAC,kBAAI,CAAC,CAAC,CAAC;QAC3C,SAAS,EAAE,CAAC,4BAAY,CAAC;QACzB,WAAW,EAAE,CAAC,kCAAe,CAAC;QAC9B,OAAO,EAAE,CAAC,4BAAY,CAAC;KACxB,CAAC;GACW,WAAW,CAAG"}

View File

@@ -1,10 +1,12 @@
import { User } from './user.entity';
import { Repository } from 'typeorm';
import { CreateUserDto } from './dto/create-user.dto';
import { ChangePasswordDto } from './dto/change-password.dto';
export declare class UsersService {
private repo;
constructor(repo: Repository<User>);
findByName(name: string): Promise<User | null>;
findByEmail(email: string): Promise<User | null>;
create(dto: CreateUserDto): Promise<User>;
changePassword(userId: number, dto: ChangePasswordDto): Promise<void>;
}

View File

@@ -17,6 +17,7 @@ const common_1 = require("@nestjs/common");
const typeorm_1 = require("@nestjs/typeorm");
const user_entity_1 = require("./user.entity");
const typeorm_2 = require("typeorm");
const bcrypt = require("bcrypt");
let UsersService = class UsersService {
repo;
constructor(repo) {
@@ -31,10 +32,21 @@ let UsersService = class UsersService {
async create(dto) {
const existing = await this.findByName(dto.name);
if (existing)
throw new common_1.BadRequestException("Already Exist User");
throw new common_1.BadRequestException("Already existed user");
const user = this.repo.create(dto);
return this.repo.save(user);
}
async changePassword(userId, dto) {
const user = await this.repo.findOne({ where: { id: userId } });
if (!user)
throw new common_1.NotFoundException("Not existed user");
const passwordValid = await bcrypt.compare(dto.currentPassword, user.password);
if (!passwordValid)
throw new common_1.BadRequestException("Not matched password");
const hashed = await bcrypt.hash(dto.newPassword, 10);
user.password = hashed;
await this.repo.save(user);
}
};
exports.UsersService = UsersService;
exports.UsersService = UsersService = __decorate([

View File

@@ -1 +1 @@
{"version":3,"file":"users.service.js","sourceRoot":"","sources":["../../src/users/users.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAiE;AACjE,6CAAmD;AACnD,+CAAqC;AACrC,qCAAqC;AAI9B,IAAM,YAAY,GAAlB,MAAM,YAAY;IACuB;IAA5C,YAA4C,IAAsB;QAAtB,SAAI,GAAJ,IAAI,CAAkB;IAAG,CAAC;IAEtE,KAAK,CAAC,UAAU,CAAC,IAAY;QACzB,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,EAAC,CAAC,CAAC;IACjD,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,KAAa;QAC3B,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,EAAC,CAAC,CAAC;IAClD,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,GAAkB;QAC3B,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,C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