Commit 021d1d1b authored by juwii's avatar juwii

feat: add app code

parent 4ce3061f
node_modules
FROM node:18-buster-slim
WORKDIR /app
COPY ./ .
EXPOSE 8080
ENTRYPOINT node dist/main.js
\ No newline at end of file
# TP-INTES
<p align="center">
<a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="200" alt="Nest Logo" /></a>
</p>
TP INTES 2022
\ No newline at end of file
[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456
[circleci-url]: https://circleci.com/gh/nestjs/nest
<p align="center">A progressive <a href="http://nodejs.org" target="_blank">Node.js</a> framework for building efficient and scalable server-side applications.</p>
<p align="center">
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a>
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a>
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/dm/@nestjs/common.svg" alt="NPM Downloads" /></a>
<a href="https://circleci.com/gh/nestjs/nest" target="_blank"><img src="https://img.shields.io/circleci/build/github/nestjs/nest/master" alt="CircleCI" /></a>
<a href="https://coveralls.io/github/nestjs/nest?branch=master" target="_blank"><img src="https://coveralls.io/repos/github/nestjs/nest/badge.svg?branch=master#9" alt="Coverage" /></a>
<a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a>
<a href="https://opencollective.com/nest#backer" target="_blank"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
<a href="https://paypal.me/kamilmysliwiec" target="_blank"><img src="https://img.shields.io/badge/Donate-PayPal-ff3f59.svg"/></a>
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://img.shields.io/badge/Support%20us-Open%20Collective-41B883.svg" alt="Support us"></a>
<a href="https://twitter.com/nestframework" target="_blank"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow"></a>
</p>
<!--[![Backers on Open Collective](https://opencollective.com/nest/backers/badge.svg)](https://opencollective.com/nest#backer)
[![Sponsors on Open Collective](https://opencollective.com/nest/sponsors/badge.svg)](https://opencollective.com/nest#sponsor)-->
## Authors
Qianyun YE
Juliette LÉTONDOT
## Description
[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository.
This is a TP from the course INTES in IMT Nord Europe.
## Installation
```bash
$ npm install
```
## Running the app
```bash
# development
$ npm run start
# watch mode
$ npm run start:dev
# production mode
$ npm run start:prod
```
## Test
```bash
# unit tests
$ npm run test
# e2e tests
$ npm run test:e2e
# test coverage
$ npm run test:cov
```
## Support
Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support).
## Stay in touch
- Author - [Kamil Myśliwiec](https://kamilmysliwiec.com)
- Website - [https://nestjs.com](https://nestjs.com/)
- Twitter - [@nestframework](https://twitter.com/nestframework)
## License
Nest is [MIT licensed](LICENSE).
import { AppService } from './app.service';
export declare class AppController {
private appService;
constructor(appService: AppService);
root(): {
message: Date;
};
}
"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.AppController = void 0;
const common_1 = require("@nestjs/common");
const app_service_1 = require("./app.service");
let AppController = class AppController {
constructor(appService) {
this.appService = appService;
}
root() {
let date = this.appService.getDate();
return { message: date };
}
};
__decorate([
(0, common_1.Get)(),
(0, common_1.Render)('index'),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], AppController.prototype, "root", null);
AppController = __decorate([
(0, common_1.Controller)({
path: "/home"
}),
__metadata("design:paramtypes", [app_service_1.AppService])
], AppController);
exports.AppController = AppController;
//# sourceMappingURL=app.controller.js.map
\ No newline at end of file
{"version":3,"file":"app.controller.js","sourceRoot":"","sources":["../src/app.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAwF;AAGxF,+CAA2C;AAKpC,IAAM,aAAa,GAAnB,MAAM,aAAa;IACxB,YAAoB,UAAsB;QAAtB,eAAU,GAAV,UAAU,CAAY;IAAG,CAAC;IAI9C,IAAI;QACF,IAAI,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;QACrC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IAC3B,CAAC;CACF,CAAA;AANC;IAAC,IAAA,YAAG,GAAE;IACL,IAAA,eAAM,EAAC,OAAO,CAAC;;;;yCAIf;AARU,aAAa;IAHzB,IAAA,mBAAU,EAAC;QACV,IAAI,EAAE,OAAO;KACd,CAAC;qCAEgC,wBAAU;GAD/B,aAAa,CASzB;AATY,sCAAa"}
\ No newline at end of file
export declare class AppModule {
}
"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.AppModule = void 0;
const common_1 = require("@nestjs/common");
const typeorm_1 = require("@nestjs/typeorm");
const app_controller_1 = require("./app.controller");
const app_service_1 = require("./app.service");
const item_entity_1 = require("./item/item.entity");
const item_module_1 = require("./item/item.module");
const hello_module_1 = require("./hello/hello.module");
const auth_module_1 = require("./auth/auth.module");
let AppModule = class AppModule {
};
AppModule = __decorate([
(0, common_1.Module)({
imports: [
typeorm_1.TypeOrmModule.forRoot({
type: 'postgres',
host: 'localhost',
port: 8075,
username: 'user',
password: 'password',
database: 'storeB',
entities: [item_entity_1.itemEntity],
synchronize: true,
}),
item_module_1.itemModule,
hello_module_1.helloModule,
auth_module_1.AuthModule
],
controllers: [
app_controller_1.AppController,
],
providers: [
app_service_1.AppService,
],
})
], AppModule);
exports.AppModule = AppModule;
//# sourceMappingURL=app.module.js.map
\ No newline at end of file
{"version":3,"file":"app.module.js","sourceRoot":"","sources":["../src/app.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,6CAAgD;AAChD,qDAAiD;AACjD,+CAA2C;AAC3C,oDAAgD;AAChD,oDAAgD;AAChD,uDAAmD;AACnD,oDAAgD;AAyBzC,IAAM,SAAS,GAAf,MAAM,SAAS;CAAG,CAAA;AAAZ,SAAS;IAvBrB,IAAA,eAAM,EAAC;QACN,OAAO,EAAE;YACP,uBAAa,CAAC,OAAO,CAAC;gBACpB,IAAI,EAAE,UAAU;gBAChB,IAAI,EAAE,WAAW;gBACjB,IAAI,EAAE,IAAI;gBACV,QAAQ,EAAE,MAAM;gBAChB,QAAQ,EAAE,UAAU;gBACpB,QAAQ,EAAE,QAAQ;gBAClB,QAAQ,EAAE,CAAC,wBAAU,CAAC;gBACtB,WAAW,EAAE,IAAI;aAClB,CAAC;YACF,wBAAU;YACV,0BAAW;YACX,wBAAU;SACX;QACD,WAAW,EAAE;YACX,8BAAa;SACd;QACD,SAAS,EAAE;YACT,wBAAU;SACX;KACF,CAAC;GACW,SAAS,CAAG;AAAZ,8BAAS"}
\ No newline at end of file
export declare class AppService {
getDate(): Date;
}
"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.AppService = void 0;
const common_1 = require("@nestjs/common");
let AppService = class AppService {
getDate() {
let date = new Date();
return date;
}
};
AppService = __decorate([
(0, common_1.Injectable)()
], AppService);
exports.AppService = AppService;
//# sourceMappingURL=app.service.js.map
\ No newline at end of file
{"version":3,"file":"app.service.js","sourceRoot":"","sources":["../src/app.service.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA4C;AAGrC,IAAM,UAAU,GAAhB,MAAM,UAAU;IACrB,OAAO;QACL,IAAI,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;QACtB,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AALY,UAAU;IADtB,IAAA,mBAAU,GAAE;GACA,UAAU,CAKtB;AALY,gCAAU"}
\ No newline at end of file
export declare const jwtConstants: {
secret: string;
};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.jwtConstants = void 0;
exports.jwtConstants = {
secret: 'secretKey',
};
//# sourceMappingURL=auth.constants.js.map
\ No newline at end of file
{"version":3,"file":"auth.constants.js","sourceRoot":"","sources":["../../src/auth/auth.constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,YAAY,GAAG;IACxB,MAAM,EAAE,WAAW;CACpB,CAAC"}
\ No newline at end of file
import { AuthService } from './auth.service';
export declare class AuthController {
private authService;
constructor(authService: AuthService);
login(req: any): Promise<{
access_token: string;
}>;
getProfile(req: any): any;
}
"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.AuthController = void 0;
const common_1 = require("@nestjs/common");
const auth_jwt_auth_guard_1 = require("./auth.jwt-auth.guard");
const auth_local_auth_guard_1 = require("./auth.local-auth.guard");
const auth_service_1 = require("./auth.service");
let AuthController = class AuthController {
constructor(authService) {
this.authService = authService;
}
async login(req) {
return this.authService.login(req.user);
}
getProfile(req) {
return req.user;
}
};
__decorate([
(0, common_1.UseGuards)(auth_local_auth_guard_1.LocalAuthGuard),
(0, common_1.Post)('auth/login'),
__param(0, (0, common_1.Request)()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Promise)
], AuthController.prototype, "login", null);
__decorate([
(0, common_1.UseGuards)(auth_jwt_auth_guard_1.JwtAuthGuard),
(0, common_1.Get)('profile'),
__param(0, (0, common_1.Request)()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], AuthController.prototype, "getProfile", null);
AuthController = __decorate([
(0, common_1.Controller)(),
__metadata("design:paramtypes", [auth_service_1.AuthService])
], AuthController);
exports.AuthController = AuthController;
//# sourceMappingURL=auth.controller.js.map
\ No newline at end of file
{"version":3,"file":"auth.controller.js","sourceRoot":"","sources":["../../src/auth/auth.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA2E;AAC3E,+DAAqD;AACrD,mEAAyD;AACzD,iDAA6C;AAGtC,IAAM,cAAc,GAApB,MAAM,cAAc;IACzB,YAAoB,WAAwB;QAAxB,gBAAW,GAAX,WAAW,CAAa;IAAG,CAAC;IAI1C,AAAN,KAAK,CAAC,KAAK,CAAY,GAAG;QACxB,OAAO,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC1C,CAAC;IAID,UAAU,CAAY,GAAG;QACvB,OAAO,GAAG,CAAC,IAAI,CAAC;IAClB,CAAC;CACF,CAAA;AATO;IAFL,IAAA,kBAAS,EAAC,sCAAc,CAAC;IACzB,IAAA,aAAI,EAAC,YAAY,CAAC;IACN,WAAA,IAAA,gBAAO,GAAE,CAAA;;;;2CAErB;AAED;IAAC,IAAA,kBAAS,EAAC,kCAAY,CAAC;IACvB,IAAA,YAAG,EAAC,SAAS,CAAC;IACH,WAAA,IAAA,gBAAO,GAAE,CAAA;;;;gDAEpB;AAbU,cAAc;IAD1B,IAAA,mBAAU,GAAE;qCAEsB,0BAAW;GADjC,cAAc,CAc1B;AAdY,wCAAc"}
\ No newline at end of file
import { CanActivate, ExecutionContext } from '@nestjs/common';
import { Observable } from 'rxjs';
export declare class RolesGuard implements CanActivate {
canActivate(context: ExecutionContext): boolean | Promise<boolean> | Observable<boolean>;
}
"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.RolesGuard = void 0;
const common_1 = require("@nestjs/common");
let RolesGuard = class RolesGuard {
canActivate(context) {
return true;
}
};
RolesGuard = __decorate([
(0, common_1.Injectable)()
], RolesGuard);
exports.RolesGuard = RolesGuard;
//# sourceMappingURL=auth.guard.js.map
\ No newline at end of file
{"version":3,"file":"auth.guard.js","sourceRoot":"","sources":["../../src/auth/auth.guard.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA2E;AAIpE,IAAM,UAAU,GAAhB,MAAM,UAAU;IACrB,WAAW,CACT,OAAyB;QAEzB,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AANY,UAAU;IADtB,IAAA,mBAAU,GAAE;GACA,UAAU,CAMtB;AANY,gCAAU"}
\ No newline at end of file
declare const JwtAuthGuard_base: import("@nestjs/passport").Type<import("@nestjs/passport").IAuthGuard>;
export declare class JwtAuthGuard extends JwtAuthGuard_base {
}
export {};
"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') {
};
JwtAuthGuard = __decorate([
(0, common_1.Injectable)()
], JwtAuthGuard);
exports.JwtAuthGuard = JwtAuthGuard;
//# sourceMappingURL=auth.jwt-auth.guard.js.map
\ No newline at end of file
{"version":3,"file":"auth.jwt-auth.guard.js","sourceRoot":"","sources":["../../src/auth/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,YAAY;IADxB,IAAA,mBAAU,GAAE;GACA,YAAY,CAA4B;AAAxC,oCAAY"}
\ No newline at end of file
import { Strategy } from 'passport-jwt';
declare const JwtStrategy_base: new (...args: any[]) => Strategy;
export declare class JwtStrategy extends JwtStrategy_base {
constructor();
validate(payload: any): Promise<{
userId: any;
username: any;
}>;
}
export {};
"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 passport_jwt_1 = require("passport-jwt");
const passport_1 = require("@nestjs/passport");
const common_1 = require("@nestjs/common");
const auth_constants_1 = require("./auth.constants");
let JwtStrategy = class JwtStrategy extends (0, passport_1.PassportStrategy)(passport_jwt_1.Strategy) {
constructor() {
super({
jwtFromRequest: passport_jwt_1.ExtractJwt.fromAuthHeaderAsBearerToken(),
ignoreExpiration: false,
secretOrKey: auth_constants_1.jwtConstants.secret,
});
}
async validate(payload) {
return { userId: payload.sub, username: payload.username };
}
};
JwtStrategy = __decorate([
(0, common_1.Injectable)(),
__metadata("design:paramtypes", [])
], JwtStrategy);
exports.JwtStrategy = JwtStrategy;
//# sourceMappingURL=auth.jwt.strategy.js.map
\ No newline at end of file
{"version":3,"file":"auth.jwt.strategy.js","sourceRoot":"","sources":["../../src/auth/auth.jwt.strategy.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+CAAoD;AACpD,+CAAoD;AACpD,2CAA4C;AAC5C,qDAAgD;AAGzC,IAAM,WAAW,GAAjB,MAAM,WAAY,SAAQ,IAAA,2BAAgB,EAAC,uBAAQ,CAAC;IACzD;QACE,KAAK,CAAC;YACJ,cAAc,EAAE,yBAAU,CAAC,2BAA2B,EAAE;YACxD,gBAAgB,EAAE,KAAK;YACvB,WAAW,EAAE,6BAAY,CAAC,MAAM;SACjC,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,WAAW;IADvB,IAAA,mBAAU,GAAE;;GACA,WAAW,CAYvB;AAZY,kCAAW"}
\ No newline at end of file
declare const LocalAuthGuard_base: import("@nestjs/passport").Type<import("@nestjs/passport").IAuthGuard>;
export declare class LocalAuthGuard extends LocalAuthGuard_base {
}
export {};
"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.LocalAuthGuard = void 0;
const common_1 = require("@nestjs/common");
const passport_1 = require("@nestjs/passport");
let LocalAuthGuard = class LocalAuthGuard extends (0, passport_1.AuthGuard)('local') {
};
LocalAuthGuard = __decorate([
(0, common_1.Injectable)()
], LocalAuthGuard);
exports.LocalAuthGuard = LocalAuthGuard;
//# sourceMappingURL=auth.local-auth.guard.js.map
\ No newline at end of file
{"version":3,"file":"auth.local-auth.guard.js","sourceRoot":"","sources":["../../src/auth/auth.local-auth.guard.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA4C;AAC5C,+CAA6C;AAGtC,IAAM,cAAc,GAApB,MAAM,cAAe,SAAQ,IAAA,oBAAS,EAAC,OAAO,CAAC;CAAG,CAAA;AAA5C,cAAc;IAD1B,IAAA,mBAAU,GAAE;GACA,cAAc,CAA8B;AAA5C,wCAAc"}
\ No newline at end of file
export declare class AuthModule {
}
"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.AuthModule = void 0;
const common_1 = require("@nestjs/common");
const auth_service_1 = require("./auth.service");
const local_strategy_1 = require("./local.strategy");
const auth_jwt_strategy_1 = require("./auth.jwt.strategy");
const users_module_1 = require("../users/users.module");
const passport_1 = require("@nestjs/passport");
const jwt_1 = require("@nestjs/jwt");
const auth_constants_1 = require("./auth.constants");
const auth_controller_1 = require("./auth.controller");
let AuthModule = class AuthModule {
};
AuthModule = __decorate([
(0, common_1.Module)({
imports: [
users_module_1.UsersModule,
passport_1.PassportModule,
jwt_1.JwtModule.register({
secret: auth_constants_1.jwtConstants.secret,
signOptions: { expiresIn: '60s' },
}),
],
controllers: [auth_controller_1.AuthController],
providers: [auth_service_1.AuthService, local_strategy_1.LocalStrategy, auth_jwt_strategy_1.JwtStrategy],
exports: [auth_service_1.AuthService],
})
], AuthModule);
exports.AuthModule = AuthModule;
//# sourceMappingURL=auth.module.js.map
\ No newline at end of file
{"version":3,"file":"auth.module.js","sourceRoot":"","sources":["../../src/auth/auth.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,iDAA6C;AAC7C,qDAAiD;AACjD,2DAAkD;AAClD,wDAAoD;AACpD,+CAAkD;AAClD,qCAAwC;AACxC,qDAAgD;AAChD,uDAAmD;AAe5C,IAAM,UAAU,GAAhB,MAAM,UAAU;CAAG,CAAA;AAAb,UAAU;IAbtB,IAAA,eAAM,EAAC;QACN,OAAO,EAAE;YACP,0BAAW;YACX,yBAAc;YACd,eAAS,CAAC,QAAQ,CAAC;gBACjB,MAAM,EAAE,6BAAY,CAAC,MAAM;gBAC3B,WAAW,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE;aAClC,CAAC;SACH;QACD,WAAW,EAAE,CAAC,gCAAc,CAAC;QAC7B,SAAS,EAAE,CAAC,0BAAW,EAAE,8BAAa,EAAE,+BAAW,CAAC;QACpD,OAAO,EAAE,CAAC,0BAAW,CAAC;KACvB,CAAC;GACW,UAAU,CAAG;AAAb,gCAAU"}
\ No newline at end of file
import { UsersService } from '../users/users.service';
import { JwtService } from '@nestjs/jwt';
export declare class AuthService {
private usersService;
private jwtService;
constructor(usersService: UsersService, jwtService: JwtService);
validateUser(username: string, pass: string): Promise<any>;
login(user: any): Promise<{
access_token: string;
}>;
}
"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 __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AuthService = void 0;
const common_1 = require("@nestjs/common");
const users_service_1 = require("../users/users.service");
const jwt_1 = require("@nestjs/jwt");
let AuthService = class AuthService {
constructor(usersService, jwtService) {
this.usersService = usersService;
this.jwtService = jwtService;
}
async validateUser(username, pass) {
const user = await this.usersService.findOne(username);
if (user && user.password === pass) {
const { password } = user, result = __rest(user, ["password"]);
return result;
}
return null;
}
async login(user) {
const payload = { username: user.username, sub: user.userId };
return {
access_token: this.jwtService.sign(payload),
};
}
};
AuthService = __decorate([
(0, common_1.Injectable)(),
__metadata("design:paramtypes", [users_service_1.UsersService,
jwt_1.JwtService])
], AuthService);
exports.AuthService = AuthService;
//# sourceMappingURL=auth.service.js.map
\ No newline at end of file
{"version":3,"file":"auth.service.js","sourceRoot":"","sources":["../../src/auth/auth.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA4C;AAC5C,0DAAsD;AACtD,qCAAyC;AAGlC,IAAM,WAAW,GAAjB,MAAM,WAAW;IACtB,YACU,YAA0B,EAC1B,UAAsB;QADtB,iBAAY,GAAZ,YAAY,CAAc;QAC1B,eAAU,GAAV,UAAU,CAAY;IAC7B,CAAC;IAEJ,KAAK,CAAC,YAAY,CAAC,QAAgB,EAAE,IAAY;QAC/C,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QACvD,IAAI,IAAI,IAAI,IAAI,CAAC,QAAQ,KAAK,IAAI,EAAE;YAClC,MAAM,EAAE,QAAQ,KAAgB,IAAI,EAAf,MAAM,UAAK,IAAI,EAA9B,YAAuB,CAAO,CAAC;YACrC,OAAO,MAAM,CAAC;SACf;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,IAAS;QACnB,MAAM,OAAO,GAAG,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,GAAG,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC;QAC9D,OAAO;YACL,YAAY,EAAE,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC;SAC5C,CAAC;IACJ,CAAC;CACF,CAAA;AArBY,WAAW;IADvB,IAAA,mBAAU,GAAE;qCAGa,4BAAY;QACd,gBAAU;GAHrB,WAAW,CAqBvB;AArBY,kCAAW"}
\ No newline at end of file
import { Strategy } from 'passport-local';
import { AuthService } from './auth.service';
declare const LocalStrategy_base: new (...args: any[]) => Strategy;
export declare class LocalStrategy extends LocalStrategy_base {
private authService;
constructor(authService: AuthService);
validate(username: string, password: string): Promise<any>;
}
export {};
"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.LocalStrategy = void 0;
const passport_local_1 = require("passport-local");
const passport_1 = require("@nestjs/passport");
const common_1 = require("@nestjs/common");
const auth_service_1 = require("./auth.service");
let LocalStrategy = class LocalStrategy extends (0, passport_1.PassportStrategy)(passport_local_1.Strategy) {
constructor(authService) {
super();
this.authService = authService;
}
async validate(username, password) {
const user = await this.authService.validateUser(username, password);
if (!user) {
throw new common_1.UnauthorizedException();
}
return user;
}
};
LocalStrategy = __decorate([
(0, common_1.Injectable)(),
__metadata("design:paramtypes", [auth_service_1.AuthService])
], LocalStrategy);
exports.LocalStrategy = LocalStrategy;
//# sourceMappingURL=local.strategy.js.map
\ No newline at end of file
{"version":3,"file":"local.strategy.js","sourceRoot":"","sources":["../../src/auth/local.strategy.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mDAA0C;AAC1C,+CAAoD;AACpD,2CAAmE;AACnE,iDAA6C;AAGtC,IAAM,aAAa,GAAnB,MAAM,aAAc,SAAQ,IAAA,2BAAgB,EAAC,yBAAQ,CAAC;IAC3D,YAAoB,WAAwB;QAC1C,KAAK,EAAE,CAAC;QADU,gBAAW,GAAX,WAAW,CAAa;IAE5C,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,QAAgB,EAAE,QAAgB;QAC/C,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QACrE,IAAI,CAAC,IAAI,EAAE;YACT,MAAM,IAAI,8BAAqB,EAAE,CAAC;SACnC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AAZY,aAAa;IADzB,IAAA,mBAAU,GAAE;qCAEsB,0BAAW;GADjC,aAAa,CAYzB;AAZY,sCAAa"}
\ No newline at end of file
import { HelloService } from './hello.service';
export declare class HelloController {
private readonly helloService;
constructor(helloService: HelloService);
getHelloWorld(): string;
}
"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.HelloController = void 0;
const common_1 = require("@nestjs/common");
const hello_service_1 = require("./hello.service");
let HelloController = class HelloController {
constructor(helloService) {
this.helloService = helloService;
}
getHelloWorld() {
return this.helloService.getHello();
}
};
__decorate([
(0, common_1.Get)(),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", String)
], HelloController.prototype, "getHelloWorld", null);
HelloController = __decorate([
(0, common_1.Controller)({
path: "/hello"
}),
__metadata("design:paramtypes", [hello_service_1.HelloService])
], HelloController);
exports.HelloController = HelloController;
//# sourceMappingURL=hello.controller.js.map
\ No newline at end of file
{"version":3,"file":"hello.controller.js","sourceRoot":"","sources":["../../src/hello/hello.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAiD;AACjD,mDAA+C;AAKxC,IAAM,eAAe,GAArB,MAAM,eAAe;IAC1B,YAA6B,YAA0B;QAA1B,iBAAY,GAAZ,YAAY,CAAc;IAAG,CAAC;IAG3D,aAAa;QACX,OAAO,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE,CAAC;IACtC,CAAC;CACF,CAAA;AAJC;IAAC,IAAA,YAAG,GAAE;;;;oDAGL;AANU,eAAe;IAH3B,IAAA,mBAAU,EAAC;QACR,IAAI,EAAE,QAAQ;KACjB,CAAC;qCAE2C,4BAAY;GAD5C,eAAe,CAO3B;AAPY,0CAAe"}
\ No newline at end of file
export declare class helloModule {
}
"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.helloModule = void 0;
const common_1 = require("@nestjs/common");
const hello_controller_1 = require("./hello.controller");
const hello_service_1 = require("./hello.service");
let helloModule = class helloModule {
};
helloModule = __decorate([
(0, common_1.Module)({
imports: [],
controllers: [hello_controller_1.HelloController],
providers: [hello_service_1.HelloService],
})
], helloModule);
exports.helloModule = helloModule;
//# sourceMappingURL=hello.module.js.map
\ No newline at end of file
{"version":3,"file":"hello.module.js","sourceRoot":"","sources":["../../src/hello/hello.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,yDAAqD;AACrD,mDAA+C;AAOxC,IAAM,WAAW,GAAjB,MAAM,WAAW;CAAG,CAAA;AAAd,WAAW;IALvB,IAAA,eAAM,EAAC;QACN,OAAO,EAAE,EAAE;QACX,WAAW,EAAE,CAAC,kCAAe,CAAC;QAC9B,SAAS,EAAE,CAAC,4BAAY,CAAC;KAC1B,CAAC;GACW,WAAW,CAAG;AAAd,kCAAW"}
\ No newline at end of file
export declare class HelloService {
getHello(): string;
}
"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.HelloService = void 0;
const common_1 = require("@nestjs/common");
let HelloService = class HelloService {
getHello() {
return 'Hello World!';
}
};
HelloService = __decorate([
(0, common_1.Injectable)()
], HelloService);
exports.HelloService = HelloService;
//# sourceMappingURL=hello.service.js.map
\ No newline at end of file
{"version":3,"file":"hello.service.js","sourceRoot":"","sources":["../../src/hello/hello.service.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA4C;AAGrC,IAAM,YAAY,GAAlB,MAAM,YAAY;IACvB,QAAQ;QACN,OAAO,cAAc,CAAC;IACxB,CAAC;CACF,CAAA;AAJY,YAAY;IADxB,IAAA,mBAAU,GAAE;GACA,YAAY,CAIxB;AAJY,oCAAY"}
\ No newline at end of file
import { itemEntity } from './item.entity';
import { ItemService } from './item.service';
export declare class itemController {
private readonly itemService;
constructor(itemService: ItemService);
findAll(): Promise<itemEntity[]>;
create(entity: itemEntity): Promise<void>;
update(entity: itemEntity): Promise<void>;
delete(entity: itemEntity): Promise<void>;
findEntitiesByRegex(name: string): Promise<itemEntity[]>;
}
"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.itemController = void 0;
const common_1 = require("@nestjs/common");
const auth_jwt_auth_guard_1 = require("../auth/auth.jwt-auth.guard");
const item_entity_1 = require("./item.entity");
const item_service_1 = require("./item.service");
let itemController = class itemController {
constructor(itemService) {
this.itemService = itemService;
}
async findAll() {
return this.itemService.findAll();
}
async create(entity) {
this.itemService.save(entity);
}
async update(entity) {
this.itemService.save(entity);
}
async delete(entity) {
this.itemService.save(entity);
}
async findEntitiesByRegex(name) {
return this.itemService.findRegexByName(name);
}
};
__decorate([
(0, common_1.Get)('item'),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", Promise)
], itemController.prototype, "findAll", null);
__decorate([
(0, common_1.UseGuards)(auth_jwt_auth_guard_1.JwtAuthGuard),
(0, common_1.Post)('item'),
__param(0, (0, common_1.Body)()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [item_entity_1.itemEntity]),
__metadata("design:returntype", Promise)
], itemController.prototype, "create", null);
__decorate([
(0, common_1.UseGuards)(auth_jwt_auth_guard_1.JwtAuthGuard),
(0, common_1.Put)('item'),
__param(0, (0, common_1.Body)()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [item_entity_1.itemEntity]),
__metadata("design:returntype", Promise)
], itemController.prototype, "update", null);
__decorate([
(0, common_1.UseGuards)(auth_jwt_auth_guard_1.JwtAuthGuard),
(0, common_1.Delete)('item'),
__param(0, (0, common_1.Body)()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [item_entity_1.itemEntity]),
__metadata("design:returntype", Promise)
], itemController.prototype, "delete", null);
__decorate([
(0, common_1.Get)('item/search/:name'),
__param(0, (0, common_1.Param)('name')),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String]),
__metadata("design:returntype", Promise)
], itemController.prototype, "findEntitiesByRegex", null);
itemController = __decorate([
(0, common_1.Controller)('service'),
__metadata("design:paramtypes", [item_service_1.ItemService])
], itemController);
exports.itemController = itemController;
//# sourceMappingURL=item.controller.js.map
\ No newline at end of file
{"version":3,"file":"item.controller.js","sourceRoot":"","sources":["../../src/item/item.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAY0B;AAC1B,qEAA4D;AAC1D,+CAA2C;AAC3C,iDAA6C;AAGtC,IAAM,cAAc,GAApB,MAAM,cAAc;IAEzB,YAA6B,WAAwB;QAAxB,gBAAW,GAAX,WAAW,CAAa;IAAG,CAAC;IAGnD,AAAN,KAAK,CAAC,OAAO;QACX,OAAO,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,CAAC;IACpC,CAAC;IAIK,AAAN,KAAK,CAAC,MAAM,CAAS,MAAkB;QACrC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAChC,CAAC;IAIK,AAAN,KAAK,CAAC,MAAM,CAAS,MAAkB;QACrC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAChC,CAAC;IAIK,AAAN,KAAK,CAAC,MAAM,CAAS,MAAkB;QACrC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAChC,CAAC;IAGK,AAAN,KAAK,CAAC,mBAAmB,CAAgB,IAAY;QACnD,OAAO,IAAI,CAAC,WAAW,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IAChD,CAAC;CAEF,CAAA;AA3BO;IADL,IAAA,YAAG,EAAC,MAAM,CAAC;;;;6CAGX;AAIK;IAFL,IAAA,kBAAS,EAAC,kCAAY,CAAC;IACvB,IAAA,aAAI,EAAC,MAAM,CAAC;IACC,WAAA,IAAA,aAAI,GAAE,CAAA;;qCAAS,wBAAU;;4CAEtC;AAIK;IAFL,IAAA,kBAAS,EAAC,kCAAY,CAAC;IACvB,IAAA,YAAG,EAAC,MAAM,CAAC;IACE,WAAA,IAAA,aAAI,GAAE,CAAA;;qCAAS,wBAAU;;4CAEtC;AAIK;IAFL,IAAA,kBAAS,EAAC,kCAAY,CAAC;IACvB,IAAA,eAAM,EAAC,MAAM,CAAC;IACD,WAAA,IAAA,aAAI,GAAE,CAAA;;qCAAS,wBAAU;;4CAEtC;AAGK;IADL,IAAA,YAAG,EAAC,mBAAmB,CAAC;IACE,WAAA,IAAA,cAAK,EAAC,MAAM,CAAC,CAAA;;;;yDAEvC;AA9BU,cAAc;IAD1B,IAAA,mBAAU,EAAC,SAAS,CAAC;qCAGsB,0BAAW;GAF1C,cAAc,CAgC1B;AAhCY,wCAAc"}
\ No newline at end of file
import { Long } from 'typeorm';
export declare class itemEntity {
id: Long;
name: string;
weight: number;
price: number;
}
"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.itemEntity = void 0;
const typeorm_1 = require("typeorm");
let itemEntity = class itemEntity {
};
__decorate([
(0, typeorm_1.PrimaryGeneratedColumn)(),
__metadata("design:type", typeorm_1.Long)
], itemEntity.prototype, "id", void 0);
__decorate([
(0, typeorm_1.Column)(),
__metadata("design:type", String)
], itemEntity.prototype, "name", void 0);
__decorate([
(0, typeorm_1.Column)({ type: 'numeric' }),
__metadata("design:type", Number)
], itemEntity.prototype, "weight", void 0);
__decorate([
(0, typeorm_1.Column)({ type: 'numeric' }),
__metadata("design:type", Number)
], itemEntity.prototype, "price", void 0);
itemEntity = __decorate([
(0, typeorm_1.Entity)()
], itemEntity);
exports.itemEntity = itemEntity;
//# sourceMappingURL=item.entity.js.map
\ No newline at end of file
{"version":3,"file":"item.entity.js","sourceRoot":"","sources":["../../src/item/item.entity.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,qCAA+E;AAGxE,IAAM,UAAU,GAAhB,MAAM,UAAU;CAYtB,CAAA;AAXC;IAAC,IAAA,gCAAsB,GAAE;8BACrB,cAAI;sCAAC;AAET;IAAC,IAAA,gBAAM,GAAE;;wCACI;AAEb;IAAC,IAAA,gBAAM,EAAC,EAAC,IAAI,EAAE,SAAS,EAAC,CAAC;;0CACX;AAEf;IAAC,IAAA,gBAAM,EAAC,EAAC,IAAI,EAAE,SAAS,EAAC,CAAC;;yCACZ;AAXH,UAAU;IADtB,IAAA,gBAAM,GAAE;GACI,UAAU,CAYtB;AAZY,gCAAU"}
\ No newline at end of file
export declare class itemModule {
}
"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.itemModule = void 0;
const common_1 = require("@nestjs/common");
const typeorm_1 = require("@nestjs/typeorm");
const item_service_1 = require("./item.service");
const item_controller_1 = require("./item.controller");
const item_entity_1 = require("./item.entity");
let itemModule = class itemModule {
};
itemModule = __decorate([
(0, common_1.Module)({
imports: [typeorm_1.TypeOrmModule.forFeature([item_entity_1.itemEntity])],
providers: [item_service_1.ItemService,
],
controllers: [item_controller_1.itemController],
})
], itemModule);
exports.itemModule = itemModule;
//# sourceMappingURL=item.module.js.map
\ No newline at end of file
{"version":3,"file":"item.module.js","sourceRoot":"","sources":["../../src/item/item.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,6CAAgD;AAChD,iDAA6C;AAC7C,uDAAmD;AACnD,+CAA2C;AAcpC,IAAM,UAAU,GAAhB,MAAM,UAAU;CAAG,CAAA;AAAb,UAAU;IAVtB,IAAA,eAAM,EAAC;QACN,OAAO,EAAE,CAAC,uBAAa,CAAC,UAAU,CAAC,CAAC,wBAAU,CAAC,CAAC,CAAC;QACjD,SAAS,EAAE,CAAC,0BAAW;SAKtB;QACD,WAAW,EAAE,CAAC,gCAAc,CAAC;KAC9B,CAAC;GACW,UAAU,CAAG;AAAb,gCAAU"}
\ No newline at end of file
import { Repository } from 'typeorm';
import { itemEntity } from './item.entity';
export declare class ItemService {
private itemRepository;
constructor(itemRepository: Repository<itemEntity>);
save(entityToSave: itemEntity): Promise<itemEntity>;
findAll(): Promise<itemEntity[]>;
delete(id: string): Promise<void>;
findFirstByName(name: string): Promise<itemEntity>;
findRegexByName(name: string): Promise<itemEntity[]>;
}
"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.ItemService = void 0;
const common_1 = require("@nestjs/common");
const typeorm_1 = require("@nestjs/typeorm");
const typeorm_2 = require("typeorm");
const item_entity_1 = require("./item.entity");
let ItemService = class ItemService {
constructor(itemRepository) {
this.itemRepository = itemRepository;
}
save(entityToSave) {
const entity = new item_entity_1.itemEntity();
entity.name = entityToSave.name;
entity.weight = entityToSave.weight;
entity.price = entityToSave.price;
return this.itemRepository.save(entity);
}
findAll() {
return this.itemRepository.find();
}
async delete(id) {
await this.itemRepository.delete(id);
}
findFirstByName(name) {
return this.itemRepository.findOneBy({ name });
}
findRegexByName(name) {
return this.itemRepository.findBy({ name });
}
};
ItemService = __decorate([
(0, common_1.Injectable)(),
__param(0, (0, typeorm_1.InjectRepository)(item_entity_1.itemEntity)),
__metadata("design:paramtypes", [typeorm_2.Repository])
], ItemService);
exports.ItemService = ItemService;
//# sourceMappingURL=item.service.js.map
\ No newline at end of file
{"version":3,"file":"item.service.js","sourceRoot":"","sources":["../../src/item/item.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA4C;AAC5C,6CAAmD;AACnD,qCAAqC;AACrC,+CAA2C;AAGpC,IAAM,WAAW,GAAjB,MAAM,WAAW;IACpB,YAEY,cAAsC;QAAtC,mBAAc,GAAd,cAAc,CAAwB;IAC/C,CAAC;IAEJ,IAAI,CAAC,YAAwB;QACzB,MAAM,MAAM,GAAG,IAAI,wBAAU,EAAE,CAAC;QAChC,MAAM,CAAC,IAAI,GAAG,YAAY,CAAC,IAAI,CAAC;QAChC,MAAM,CAAC,MAAM,GAAG,YAAY,CAAC,MAAM,CAAC;QACpC,MAAM,CAAC,KAAK,GAAG,YAAY,CAAC,KAAK,CAAC;QAClC,OAAO,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC5C,CAAC;IAED,OAAO;QACH,OAAO,IAAI,CAAC,cAAc,CAAC,IAAI,EAAE,CAAC;IACtC,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,EAAU;QACnB,MAAM,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IACzC,CAAC;IAED,eAAe,CAAC,IAAY;QACxB,OAAO,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;IACnD,CAAC;IAED,eAAe,CAAC,IAAY;QACxB,OAAO,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;IAChD,CAAC;CACJ,CAAA;AA7BY,WAAW;IADvB,IAAA,mBAAU,GAAE;IAGJ,WAAA,IAAA,0BAAgB,EAAC,wBAAU,CAAC,CAAA;qCACL,oBAAU;GAH7B,WAAW,CA6BvB;AA7BY,kCAAW"}
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = require("path");
const core_1 = require("@nestjs/core");
const app_module_1 = require("./app.module");
async function bootstrap() {
const app = await core_1.NestFactory.create(app_module_1.AppModule);
app.useStaticAssets((0, path_1.join)(__dirname, '..', 'public'));
app.setBaseViewsDir((0, path_1.join)(__dirname, '..', 'views'));
app.setViewEngine('hbs');
await app.listen(3000);
}
bootstrap();
//# sourceMappingURL=main.js.map
\ No newline at end of file
{"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";;AACA,+BAA4B;AAE5B,uCAA2C;AAC3C,6CAAyC;AAGzC,KAAK,UAAU,SAAS;IACtB,MAAM,GAAG,GAAG,MAAM,kBAAW,CAAC,MAAM,CAClC,sBAAS,CACV,CAAC;IAEF,GAAG,CAAC,eAAe,CAAC,IAAA,WAAI,EAAC,SAAS,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC;IACrD,GAAG,CAAC,eAAe,CAAC,IAAA,WAAI,EAAC,SAAS,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;IACpD,GAAG,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IAEzB,MAAM,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AACzB,CAAC;AACD,SAAS,EAAE,CAAC"}
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
export declare class UsersModule {
}
"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.UsersModule = void 0;
const common_1 = require("@nestjs/common");
const users_service_1 = require("./users.service");
let UsersModule = class UsersModule {
};
UsersModule = __decorate([
(0, common_1.Module)({
providers: [users_service_1.UsersService],
exports: [users_service_1.UsersService],
})
], UsersModule);
exports.UsersModule = UsersModule;
//# sourceMappingURL=users.module.js.map
\ No newline at end of file
{"version":3,"file":"users.module.js","sourceRoot":"","sources":["../../src/users/users.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,mDAA+C;AAMxC,IAAM,WAAW,GAAjB,MAAM,WAAW;CAAG,CAAA;AAAd,WAAW;IAJvB,IAAA,eAAM,EAAC;QACN,SAAS,EAAE,CAAC,4BAAY,CAAC;QACzB,OAAO,EAAE,CAAC,4BAAY,CAAC;KACxB,CAAC;GACW,WAAW,CAAG;AAAd,kCAAW"}
\ No newline at end of file
export declare type User = any;
export declare class UsersService {
private readonly users;
findOne(username: string): Promise<User | undefined>;
}
"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.UsersService = void 0;
const common_1 = require("@nestjs/common");
let UsersService = class UsersService {
constructor() {
this.users = [
{
userId: 1,
username: 'Ju',
password: 'liette',
},
{
userId: 2,
username: 'Jean',
password: 'Bon',
},
];
}
async findOne(username) {
return this.users.find(user => user.username === username);
}
};
UsersService = __decorate([
(0, common_1.Injectable)()
], UsersService);
exports.UsersService = UsersService;
//# sourceMappingURL=users.service.js.map
\ No newline at end of file
{"version":3,"file":"users.service.js","sourceRoot":"","sources":["../../src/users/users.service.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA4C;AAMrC,IAAM,YAAY,GAAlB,MAAM,YAAY;IAAlB;QACY,UAAK,GAAG;YACvB;gBACE,MAAM,EAAE,CAAC;gBACT,QAAQ,EAAE,IAAI;gBACd,QAAQ,EAAE,QAAQ;aACnB;YACD;gBACE,MAAM,EAAE,CAAC;gBACT,QAAQ,EAAE,MAAM;gBAChB,QAAQ,EAAE,KAAK;aAChB;SACF,CAAC;IAKJ,CAAC;IAHC,KAAK,CAAC,OAAO,CAAC,QAAgB;QAC5B,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,QAAQ,KAAK,QAAQ,CAAC,CAAC;IAC7D,CAAC;CACF,CAAA;AAjBY,YAAY;IADxB,IAAA,mBAAU,GAAE;GACA,YAAY,CAiBxB;AAjBY,oCAAY"}
\ No newline at end of file
{
"$schema": "https://json.schemastore.org/nest-cli",
"collection": "@nestjs/schematics",
"sourceRoot": "src"
}
This diff is collapsed.
{
"name": "store-b",
"version": "0.0.1",
"description": "",
"author": "",
"private": true,
"license": "UNLICENSED",
"scripts": {
"prebuild": "rimraf dist",
"build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "nest start",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json"
},
"dependencies": {
"@nestjs/common": "^9.0.0",
"@nestjs/core": "^9.0.0",
"@nestjs/jwt": "^9.0.0",
"@nestjs/passport": "^9.0.0",
"@nestjs/platform-express": "^9.0.0",
"@nestjs/serve-static": "^3.0.0",
"@nestjs/typeorm": "^9.0.1",
"passport": "^0.6.0",
"passport-jwt": "^4.0.0",
"passport-local": "^1.0.0",
"pg": "^8.8.0",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^7.2.0",
"typeorm": "^0.3.10"
},
"devDependencies": {
"@nestjs/cli": "^9.0.0",
"@nestjs/schematics": "^9.0.0",
"@nestjs/testing": "^9.0.0",
"@types/express": "^4.17.13",
"@types/jest": "28.1.8",
"@types/node": "^16.0.0",
"@types/passport-jwt": "^3.0.6",
"@types/passport-local": "^1.0.34",
"@types/supertest": "^2.0.11",
"@typescript-eslint/eslint-plugin": "^5.0.0",
"@typescript-eslint/parser": "^5.0.0",
"eslint": "^8.0.1",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^4.0.0",
"jest": "28.1.3",
"prettier": "^2.3.2",
"source-map-support": "^0.5.20",
"supertest": "^6.1.3",
"ts-jest": "28.0.8",
"ts-loader": "^9.2.3",
"ts-node": "^10.0.0",
"tsconfig-paths": "4.1.0",
"typescript": "^4.7.4"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": "src",
"testRegex": ".*\\.spec\\.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"collectCoverageFrom": [
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
}
}
import { Test, TestingModule } from '@nestjs/testing';
import { AppController } from './app.controller';
import { AppService } from './app.service';
/*describe('AppController', () => {
let appController: AppController;
beforeEach(async () => {
const app: TestingModule = await Test.createTestingModule({
controllers: [AppController],
providers: [AppService],
}).compile();
appController = app.get<AppController>(AppController);
});
describe('root', () => {
it('should return "Hello World!"', () => {
expect(appController.getHello()).toBe('Hello World!');
});
});
});*/
import { Controller, Get, Request, Post, UseGuards, Res, Render } from '@nestjs/common';
import { JwtAuthGuard } from './auth/auth.jwt-auth.guard';
import { LocalAuthGuard } from './auth/auth.local-auth.guard';
import { AppService } from './app.service';
@Controller({
path: "/home"
})
export class AppController {
constructor(private appService: AppService) {}
@Get()
@Render('index')
root() {
let date = this.appService.getDate();
return { message: date };
}
}
\ No newline at end of file
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { itemEntity } from './item/item.entity';
import { itemModule } from './item/item.module';
import { helloModule } from './hello/hello.module';
import { AuthModule } from './auth/auth.module';
@Module({
imports: [
TypeOrmModule.forRoot({
type: 'postgres',
host: 'localhost',
port: 8075,
username: 'user',
password: 'password',
database: 'storeB',
entities: [itemEntity],
synchronize: true,
}),
itemModule,
helloModule,
AuthModule
],
controllers: [
AppController,
],
providers: [
AppService,
],
})
export class AppModule {}
import { Injectable } from '@nestjs/common';
@Injectable()
export class AppService {
getDate(): Date {
let date = new Date();
return date;
}
}
export const jwtConstants = {
secret: 'secretKey',
};
\ No newline at end of file
import { Controller, Get, Request, Post, UseGuards } from '@nestjs/common';
import { JwtAuthGuard } from './auth.jwt-auth.guard';
import { LocalAuthGuard } from './auth.local-auth.guard';
import { AuthService } from './auth.service';
@Controller()
export class AuthController {
constructor(private authService: AuthService) {}
@UseGuards(LocalAuthGuard)
@Post('auth/login')
async login(@Request() req) {
return this.authService.login(req.user);
}
@UseGuards(JwtAuthGuard)
@Get('profile')
getProfile(@Request() req) {
return req.user;
}
}
import { Injectable } from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
@Injectable()
export class JwtAuthGuard extends AuthGuard('jwt') {}
import { ExtractJwt, Strategy } from 'passport-jwt';
import { PassportStrategy } from '@nestjs/passport';
import { Injectable } from '@nestjs/common';
import { jwtConstants } from './auth.constants';
@Injectable()
export class JwtStrategy extends PassportStrategy(Strategy) {
constructor() {
super({
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
ignoreExpiration: false,
secretOrKey: jwtConstants.secret,
});
}
async validate(payload: any) {
return { userId: payload.sub, username: payload.username };
}
}
\ No newline at end of file
import { Injectable } from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
@Injectable()
export class LocalAuthGuard extends AuthGuard('local') {}
\ No newline at end of file
import { Module } from '@nestjs/common';
import { AuthService } from './auth.service';
import { LocalStrategy } from './local.strategy';
import { JwtStrategy } from './auth.jwt.strategy';
import { UsersModule } from '../users/users.module';
import { PassportModule } from '@nestjs/passport';
import { JwtModule } from '@nestjs/jwt';
import { jwtConstants } from './auth.constants';
import { AuthController } from './auth.controller';
@Module({
imports: [
UsersModule,
PassportModule,
JwtModule.register({
secret: jwtConstants.secret,
signOptions: { expiresIn: '60s' },
}),
],
controllers: [AuthController],
providers: [AuthService, LocalStrategy, JwtStrategy],
exports: [AuthService],
})
export class AuthModule {}
\ No newline at end of file
import { Injectable } from '@nestjs/common';
import { UsersService } from '../users/users.service';
import { JwtService } from '@nestjs/jwt';
@Injectable()
export class AuthService {
constructor(
private usersService: UsersService,
private jwtService: JwtService
) {}
async validateUser(username: string, pass: string): Promise<any> {
const user = await this.usersService.findOne(username);
if (user && user.password === pass) {
const { password, ...result } = user;
return result;
}
return null;
}
async login(user: any) {
const payload = { username: user.username, sub: user.userId };
return {
access_token: this.jwtService.sign(payload),
};
}
}
\ No newline at end of file
import { Strategy } from 'passport-local';
import { PassportStrategy } from '@nestjs/passport';
import { Injectable, UnauthorizedException } from '@nestjs/common';
import { AuthService } from './auth.service';
@Injectable()
export class LocalStrategy extends PassportStrategy(Strategy) {
constructor(private authService: AuthService) {
super();
}
async validate(username: string, password: string): Promise<any> {
const user = await this.authService.validateUser(username, password);
if (!user) {
throw new UnauthorizedException();
}
return user;
}
}
\ No newline at end of file
import { Controller, Get } from '@nestjs/common';
import { HelloService } from './hello.service';
@Controller({
path: "/hello"
})
export class HelloController {
constructor(private readonly helloService: HelloService) {}
@Get()
getHelloWorld(): string {
return this.helloService.getHello();
}
}
\ No newline at end of file
import { Module } from '@nestjs/common';
import { HelloController } from './hello.controller';
import { HelloService } from './hello.service';
@Module({
imports: [],
controllers: [HelloController],
providers: [HelloService],
})
export class helloModule {}
\ No newline at end of file
import { Injectable } from '@nestjs/common';
@Injectable()
export class HelloService {
getHello(): string {
return 'Hello World!';
}
}
\ No newline at end of file
import {
Body,
Controller,
Delete,
Get,
Param,
Post,
ParseIntPipe,
Put,
Res,
HttpStatus,
UseGuards,
} from '@nestjs/common';
import { JwtAuthGuard } from 'src/auth/auth.jwt-auth.guard';
import { itemEntity } from './item.entity';
import { ItemService } from './item.service';
@Controller('service')
export class itemController {
constructor(private readonly itemService: ItemService) {}
@Get('item')
async findAll(): Promise<itemEntity[]> {
return this.itemService.findAll();
}
@UseGuards(JwtAuthGuard)
@Post('item')
async create(@Body() entity: itemEntity) {
this.itemService.save(entity);
}
@UseGuards(JwtAuthGuard)
@Put('item')
async update(@Body() entity: itemEntity): Promise<void> {
this.itemService.save(entity);
}
@UseGuards(JwtAuthGuard)
@Delete('item')
async delete(@Body() entity: itemEntity): Promise<void> {
this.itemService.save(entity);
}
@Get('item/search/:name')
async findEntitiesByRegex(@Param('name') name: string): Promise<itemEntity[]> {
return this.itemService.findRegexByName(name);
}
}
\ No newline at end of file
import { type } from 'os';
import { Entity, Column, PrimaryGeneratedColumn, Long, Double } from 'typeorm';
@Entity()
export class itemEntity {
@PrimaryGeneratedColumn()
id: Long;
@Column()
name: string;
@Column({type: 'numeric'})
weight: number;
@Column({type: 'numeric'})
price: number;
}
\ No newline at end of file
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ItemService } from './item.service';
import { itemController } from './item.controller';
import { itemEntity } from './item.entity';
import { JwtAuthGuard } from 'src/auth/auth.jwt-auth.guard';
import { APP_GUARD } from '@nestjs/core';
@Module({
imports: [TypeOrmModule.forFeature([itemEntity])],
providers: [ItemService,
/*{
provide: APP_GUARD,
useClass: JwtAuthGuard,
}*/
],
controllers: [itemController],
})
export class itemModule {}
\ No newline at end of file
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { itemEntity } from './item.entity';
@Injectable()
export class ItemService {
constructor(
@InjectRepository(itemEntity)
private itemRepository: Repository<itemEntity>,
) {}
save(entityToSave: itemEntity): Promise<itemEntity> {
const entity = new itemEntity();
entity.name = entityToSave.name;
entity.weight = entityToSave.weight;
entity.price = entityToSave.price;
return this.itemRepository.save(entity);
}
findAll(): Promise<itemEntity[]> {
return this.itemRepository.find();
}
async delete(id: string): Promise<void> {
await this.itemRepository.delete(id);
}
findFirstByName(name: string): Promise<itemEntity> {
return this.itemRepository.findOneBy({ name });
}
findRegexByName(name: string): Promise<itemEntity[]> {
return this.itemRepository.findBy({ name });
}
}
\ No newline at end of file
import { NestExpressApplication } from '@nestjs/platform-express';
import { join } from 'path';
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
// = main en java
async function bootstrap() {
const app = await NestFactory.create<NestExpressApplication>(
AppModule,
);
app.useStaticAssets(join(__dirname, '..', 'public'));
app.setBaseViewsDir(join(__dirname, '..', 'views'));
app.setViewEngine('hbs');
await app.listen(3000);
}
bootstrap();
import { Module } from '@nestjs/common';
import { UsersService } from './users.service';
@Module({
providers: [UsersService],
exports: [UsersService],
})
export class UsersModule {}
\ No newline at end of file
import { Injectable } from '@nestjs/common';
// This should be a real class/interface representing a user entity
export type User = any;
@Injectable()
export class UsersService {
private readonly users = [
{
userId: 1,
username: 'Ju',
password: 'liette',
},
{
userId: 2,
username: 'Jean',
password: 'Bon',
},
];
async findOne(username: string): Promise<User | undefined> {
return this.users.find(user => user.username === username);
}
}
\ No newline at end of file
import { Test, TestingModule } from '@nestjs/testing';
import { INestApplication } from '@nestjs/common';
import * as request from 'supertest';
import { AppModule } from './../src/app.module';
describe('AppController (e2e)', () => {
let app: INestApplication;
beforeEach(async () => {
const moduleFixture: TestingModule = await Test.createTestingModule({
imports: [AppModule],
}).compile();
app = moduleFixture.createNestApplication();
await app.init();
});
it('/ (GET)', () => {
return request(app.getHttpServer())
.get('/')
.expect(200)
.expect('Hello World!');
});
});
{
"moduleFileExtensions": ["js", "json", "ts"],
"rootDir": ".",
"testEnvironment": "node",
"testRegex": ".e2e-spec.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
}
}
{
"extends": "./tsconfig.json",
"exclude": ["node_modules", "test", "dist", "**/*spec.ts"]
}
{
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"target": "es2017",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./",
"incremental": true,
"skipLibCheck": true,
"strictNullChecks": false,
"noImplicitAny": false,
"strictBindCallApply": false,
"forceConsistentCasingInFileNames": false,
"noFallthroughCasesInSwitch": false
}
}
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment