Spaces:
Sleeping
Sleeping
Merge pull request #4 from PBL6-team-CATS/feature/login
Browse files- backend/package-lock.json +34 -0
- backend/package.json +1 -0
- backend/src/app.module.ts +4 -0
- backend/src/modules/authentication/authentication.controller.spec.ts +20 -0
- backend/src/modules/authentication/authentication.controller.ts +34 -0
- backend/src/modules/authentication/authentication.module.ts +9 -0
- backend/src/modules/authentication/authentication.service.spec.ts +18 -0
- backend/src/modules/authentication/authentication.service.ts +26 -0
- backend/src/modules/authentication/dto/create-authentication.dto.ts +1 -0
- backend/src/modules/authentication/dto/update-authentication.dto.ts +4 -0
- backend/src/modules/authentication/enums/index.ts +8 -0
- backend/src/modules/authentication/rbac-policy.ts +9 -0
backend/package-lock.json
CHANGED
@@ -17,6 +17,7 @@
|
|
17 |
"@nestjs/typeorm": "^10.0.2",
|
18 |
"dotenv": "^16.4.5",
|
19 |
"mysql2": "^3.11.3",
|
|
|
20 |
"pg": "^8.13.0",
|
21 |
"reflect-metadata": "^0.2.0",
|
22 |
"rxjs": "^7.8.1",
|
@@ -2527,6 +2528,15 @@
|
|
2527 |
"node": ">= 0.6"
|
2528 |
}
|
2529 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2530 |
"node_modules/acorn": {
|
2531 |
"version": "8.12.1",
|
2532 |
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.12.1.tgz",
|
@@ -6525,6 +6535,24 @@
|
|
6525 |
"integrity": "sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==",
|
6526 |
"dev": true
|
6527 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6528 |
"node_modules/node-abort-controller": {
|
6529 |
"version": "3.1.1",
|
6530 |
"resolved": "https://registry.npmjs.org/node-abort-controller/-/node-abort-controller-3.1.1.tgz",
|
@@ -6580,6 +6608,12 @@
|
|
6580 |
"node": ">=0.10.0"
|
6581 |
}
|
6582 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
6583 |
"node_modules/npm-run-path": {
|
6584 |
"version": "4.0.1",
|
6585 |
"resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-4.0.1.tgz",
|
|
|
17 |
"@nestjs/typeorm": "^10.0.2",
|
18 |
"dotenv": "^16.4.5",
|
19 |
"mysql2": "^3.11.3",
|
20 |
+
"nest-access-control": "^3.1.0",
|
21 |
"pg": "^8.13.0",
|
22 |
"reflect-metadata": "^0.2.0",
|
23 |
"rxjs": "^7.8.1",
|
|
|
2528 |
"node": ">= 0.6"
|
2529 |
}
|
2530 |
},
|
2531 |
+
"node_modules/accesscontrol": {
|
2532 |
+
"version": "2.2.1",
|
2533 |
+
"resolved": "https://registry.npmjs.org/accesscontrol/-/accesscontrol-2.2.1.tgz",
|
2534 |
+
"integrity": "sha512-52EvFk/J9EF+w4mYQoKnOTkEMj01R1U5n2fc1dai6x1xkgOks3DGkx01qQL2cKFxGmE4Tn1krAU3jJA9L1NMkg==",
|
2535 |
+
"license": "MIT",
|
2536 |
+
"dependencies": {
|
2537 |
+
"notation": "^1.3.6"
|
2538 |
+
}
|
2539 |
+
},
|
2540 |
"node_modules/acorn": {
|
2541 |
"version": "8.12.1",
|
2542 |
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.12.1.tgz",
|
|
|
6535 |
"integrity": "sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==",
|
6536 |
"dev": true
|
6537 |
},
|
6538 |
+
"node_modules/nest-access-control": {
|
6539 |
+
"version": "3.1.0",
|
6540 |
+
"resolved": "https://registry.npmjs.org/nest-access-control/-/nest-access-control-3.1.0.tgz",
|
6541 |
+
"integrity": "sha512-rg8OWIcvA2gGiSjnl141RDg2B+R7YgyYgCl3D67NcK7/1TXoTJCdqSyFysYXzkiHiXZOvANKYkvke//p6Yzl8g==",
|
6542 |
+
"license": "MIT",
|
6543 |
+
"dependencies": {
|
6544 |
+
"accesscontrol": "^2.2.1",
|
6545 |
+
"tslib": "^2.6.2"
|
6546 |
+
},
|
6547 |
+
"peerDependencies": {
|
6548 |
+
"@nestjs/graphql": "^7.0.0 || ^8.0.0 || ^9.0.0 || ^10.0.0 || ^11.0.0 || ^12.0.0"
|
6549 |
+
},
|
6550 |
+
"peerDependenciesMeta": {
|
6551 |
+
"@nestjs/graphql": {
|
6552 |
+
"optional": true
|
6553 |
+
}
|
6554 |
+
}
|
6555 |
+
},
|
6556 |
"node_modules/node-abort-controller": {
|
6557 |
"version": "3.1.1",
|
6558 |
"resolved": "https://registry.npmjs.org/node-abort-controller/-/node-abort-controller-3.1.1.tgz",
|
|
|
6608 |
"node": ">=0.10.0"
|
6609 |
}
|
6610 |
},
|
6611 |
+
"node_modules/notation": {
|
6612 |
+
"version": "1.3.6",
|
6613 |
+
"resolved": "https://registry.npmjs.org/notation/-/notation-1.3.6.tgz",
|
6614 |
+
"integrity": "sha512-DIuJmrP/Gg1DcXKaApsqcjsJD6jEccqKSfmU3BUx/f1GHsMiTJh70cERwYc64tOmTRTARCeMwkqNNzjh3AHhiw==",
|
6615 |
+
"license": "MIT"
|
6616 |
+
},
|
6617 |
"node_modules/npm-run-path": {
|
6618 |
"version": "4.0.1",
|
6619 |
"resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-4.0.1.tgz",
|
backend/package.json
CHANGED
@@ -33,6 +33,7 @@
|
|
33 |
"@nestjs/typeorm": "^10.0.2",
|
34 |
"dotenv": "^16.4.5",
|
35 |
"mysql2": "^3.11.3",
|
|
|
36 |
"pg": "^8.13.0",
|
37 |
"reflect-metadata": "^0.2.0",
|
38 |
"rxjs": "^7.8.1",
|
|
|
33 |
"@nestjs/typeorm": "^10.0.2",
|
34 |
"dotenv": "^16.4.5",
|
35 |
"mysql2": "^3.11.3",
|
36 |
+
"nest-access-control": "^3.1.0",
|
37 |
"pg": "^8.13.0",
|
38 |
"reflect-metadata": "^0.2.0",
|
39 |
"rxjs": "^7.8.1",
|
backend/src/app.module.ts
CHANGED
@@ -9,6 +9,9 @@ import { AppLoggerMiddleware } from './common/middlewares/app-logger.middleware.
|
|
9 |
import { DeviceInfoMiddleware } from './common/middlewares/device-info.middleware.js';
|
10 |
import { UserModule } from './modules/user/user.module.js';
|
11 |
import { BranchModule } from './modules/branch/branch.module.js';
|
|
|
|
|
|
|
12 |
|
13 |
@Module({
|
14 |
imports: [
|
@@ -22,6 +25,7 @@ import { BranchModule } from './modules/branch/branch.module.js';
|
|
22 |
}),
|
23 |
UserModule,
|
24 |
BranchModule,
|
|
|
25 |
],
|
26 |
controllers: [AppController],
|
27 |
providers: [AppService],
|
|
|
9 |
import { DeviceInfoMiddleware } from './common/middlewares/device-info.middleware.js';
|
10 |
import { UserModule } from './modules/user/user.module.js';
|
11 |
import { BranchModule } from './modules/branch/branch.module.js';
|
12 |
+
import { AuthenticationModule } from './modules/authentication/authentication.module';
|
13 |
+
import {AccessControlModule, ACGuard} from 'nest-access-control'
|
14 |
+
import { APP_GUARD } from '@nestjs/core';
|
15 |
|
16 |
@Module({
|
17 |
imports: [
|
|
|
25 |
}),
|
26 |
UserModule,
|
27 |
BranchModule,
|
28 |
+
AuthenticationModule,
|
29 |
],
|
30 |
controllers: [AppController],
|
31 |
providers: [AppService],
|
backend/src/modules/authentication/authentication.controller.spec.ts
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { Test, TestingModule } from '@nestjs/testing';
|
2 |
+
import { AuthenticationController } from './authentication.controller';
|
3 |
+
import { AuthenticationService } from './authentication.service';
|
4 |
+
|
5 |
+
describe('AuthenticationController', () => {
|
6 |
+
let controller: AuthenticationController;
|
7 |
+
|
8 |
+
beforeEach(async () => {
|
9 |
+
const module: TestingModule = await Test.createTestingModule({
|
10 |
+
controllers: [AuthenticationController],
|
11 |
+
providers: [AuthenticationService],
|
12 |
+
}).compile();
|
13 |
+
|
14 |
+
controller = module.get<AuthenticationController>(AuthenticationController);
|
15 |
+
});
|
16 |
+
|
17 |
+
it('should be defined', () => {
|
18 |
+
expect(controller).toBeDefined();
|
19 |
+
});
|
20 |
+
});
|
backend/src/modules/authentication/authentication.controller.ts
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
|
2 |
+
import { AuthenticationService } from './authentication.service';
|
3 |
+
import { CreateAuthenticationDto } from './dto/create-authentication.dto';
|
4 |
+
import { UpdateAuthenticationDto } from './dto/update-authentication.dto';
|
5 |
+
|
6 |
+
@Controller('authentication')
|
7 |
+
export class AuthenticationController {
|
8 |
+
constructor(private readonly authenticationService: AuthenticationService) {}
|
9 |
+
|
10 |
+
@Post()
|
11 |
+
create(@Body() createAuthenticationDto: CreateAuthenticationDto) {
|
12 |
+
return this.authenticationService.create(createAuthenticationDto);
|
13 |
+
}
|
14 |
+
|
15 |
+
@Get()
|
16 |
+
findAll() {
|
17 |
+
return this.authenticationService.findAll();
|
18 |
+
}
|
19 |
+
|
20 |
+
@Get(':id')
|
21 |
+
findOne(@Param('id') id: string) {
|
22 |
+
return this.authenticationService.findOne(+id);
|
23 |
+
}
|
24 |
+
|
25 |
+
@Patch(':id')
|
26 |
+
update(@Param('id') id: string, @Body() updateAuthenticationDto: UpdateAuthenticationDto) {
|
27 |
+
return this.authenticationService.update(+id, updateAuthenticationDto);
|
28 |
+
}
|
29 |
+
|
30 |
+
@Delete(':id')
|
31 |
+
remove(@Param('id') id: string) {
|
32 |
+
return this.authenticationService.remove(+id);
|
33 |
+
}
|
34 |
+
}
|
backend/src/modules/authentication/authentication.module.ts
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { Module } from '@nestjs/common';
|
2 |
+
import { AuthenticationService } from './authentication.service';
|
3 |
+
import { AuthenticationController } from './authentication.controller';
|
4 |
+
|
5 |
+
@Module({
|
6 |
+
controllers: [AuthenticationController],
|
7 |
+
providers: [AuthenticationService],
|
8 |
+
})
|
9 |
+
export class AuthenticationModule {}
|
backend/src/modules/authentication/authentication.service.spec.ts
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { Test, TestingModule } from '@nestjs/testing';
|
2 |
+
import { AuthenticationService } from './authentication.service';
|
3 |
+
|
4 |
+
describe('AuthenticationService', () => {
|
5 |
+
let service: AuthenticationService;
|
6 |
+
|
7 |
+
beforeEach(async () => {
|
8 |
+
const module: TestingModule = await Test.createTestingModule({
|
9 |
+
providers: [AuthenticationService],
|
10 |
+
}).compile();
|
11 |
+
|
12 |
+
service = module.get<AuthenticationService>(AuthenticationService);
|
13 |
+
});
|
14 |
+
|
15 |
+
it('should be defined', () => {
|
16 |
+
expect(service).toBeDefined();
|
17 |
+
});
|
18 |
+
});
|
backend/src/modules/authentication/authentication.service.ts
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { Injectable } from '@nestjs/common';
|
2 |
+
import { CreateAuthenticationDto } from './dto/create-authentication.dto';
|
3 |
+
import { UpdateAuthenticationDto } from './dto/update-authentication.dto';
|
4 |
+
|
5 |
+
@Injectable()
|
6 |
+
export class AuthenticationService {
|
7 |
+
create(createAuthenticationDto: CreateAuthenticationDto) {
|
8 |
+
return 'This action adds a new authentication';
|
9 |
+
}
|
10 |
+
|
11 |
+
findAll() {
|
12 |
+
return `This action returns all authentication`;
|
13 |
+
}
|
14 |
+
|
15 |
+
findOne(id: number) {
|
16 |
+
return `This action returns a #${id} authentication`;
|
17 |
+
}
|
18 |
+
|
19 |
+
update(id: number, updateAuthenticationDto: UpdateAuthenticationDto) {
|
20 |
+
return `This action updates a #${id} authentication`;
|
21 |
+
}
|
22 |
+
|
23 |
+
remove(id: number) {
|
24 |
+
return `This action removes a #${id} authentication`;
|
25 |
+
}
|
26 |
+
}
|
backend/src/modules/authentication/dto/create-authentication.dto.ts
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
export class CreateAuthenticationDto {}
|
backend/src/modules/authentication/dto/update-authentication.dto.ts
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { PartialType } from '@nestjs/mapped-types';
|
2 |
+
import { CreateAuthenticationDto } from './create-authentication.dto';
|
3 |
+
|
4 |
+
export class UpdateAuthenticationDto extends PartialType(CreateAuthenticationDto) {}
|
backend/src/modules/authentication/enums/index.ts
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
export enum Role {
|
2 |
+
CUSTOMER = 'CUSTOMER',
|
3 |
+
ADMIN = 'ADMIN',
|
4 |
+
BRANCH_MANAGER = 'BRANCH_MANAGER',
|
5 |
+
AREA_MANAGER = 'AREA_MANAGER',
|
6 |
+
STAFF = 'STAFF',
|
7 |
+
SHIPPER = 'SHIPPER'
|
8 |
+
}
|
backend/src/modules/authentication/rbac-policy.ts
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { RolesBuilder } from 'nest-access-control';
|
2 |
+
import { Role } from './enums';
|
3 |
+
|
4 |
+
export const RBAC_POLICY: RolesBuilder = new RolesBuilder();
|
5 |
+
|
6 |
+
// prettier-ignore
|
7 |
+
RBAC_POLICY
|
8 |
+
.grant(Role.ADMIN)
|
9 |
+
.read()
|