Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/d-rec/drec-origin into D…
Browse files Browse the repository at this point in the history
…R-797
  • Loading branch information
Aish1990 committed May 15, 2024
2 parents 9d4f1b6 + a1a810c commit adbb65d
Show file tree
Hide file tree
Showing 57 changed files with 1,435 additions and 859 deletions.
13 changes: 9 additions & 4 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Install tooling
run: |
npm i -g @microsoft/rush
npm i -g pnpm@6
npm i -g pnpm@7
- name: Install drec-origin
run: |
Expand All @@ -47,13 +47,18 @@ jobs:
- name: Install tooling
run: |
npm i -g @microsoft/rush
npm i -g pnpm@6
npm i -g pnpm@7
- name: Install drec-origin
run: |
rush install
- name: Run ESLint
- name: Run ESLint (error)
working-directory: apps/drec-api
run: pnpm run lint:error
continue-on-error: true

- name: Run ESLint (all)
working-directory: apps/drec-api
run: pnpm run lint
continue-on-error: true
Expand All @@ -72,7 +77,7 @@ jobs:
- name: Install tooling
run: |
npm i -g @microsoft/rush
npm i -g pnpm@6
npm i -g pnpm@7
- name: Install drec-origin
run: |
Expand Down
5 changes: 2 additions & 3 deletions apps/drec-api/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ module.exports = {
},
plugins: ['@typescript-eslint/eslint-plugin'],
extends: [
// Temporarily disable `eslint:recommended` until other lint issues have been fixed
// 'eslint:recommended',
// 'plugin:@typescript-eslint/eslint-recommended',
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'prettier',
'prettier/@typescript-eslint',
Expand Down
2 changes: 1 addition & 1 deletion apps/drec-api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ RUN npm cache clean --force
COPY . .

RUN npm i -g @microsoft/rush
RUN npm i -g pnpm@6
RUN npm i -g pnpm@7

WORKDIR /dist/src/app/apps/drec-api

Expand Down
5 changes: 3 additions & 2 deletions apps/drec-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
"redis:drop": "redis-cli flushall",
"prettier": "prettier --check --config-precedence file-override './{src,migrations,test}/**/*'",
"prettier:fix": "prettier --write --config-precedence file-override './{src,migrations,test}/**/*'",
"lint": "eslint \"{src,migrations,test}/**/*{.ts,.tsx}\" --no-error-on-unmatched-pattern",
"lint:fix": "eslint \"{src,migrations,test}/**/*{.ts,.tsx}\" --fix --no-error-on-unmatched-pattern",
"lint": "eslint \"{src,migrations,test}/**/*{.ts,.tsx}\"",
"lint:error": "eslint \"{src,migrations,test}/**/*{.ts,.tsx}\" --quiet",
"lint:fix": "eslint \"{src,migrations,test}/**/*{.ts,.tsx}\" --fix",
"migrate": "pnpm typeorm:run:issuer && pnpm typeorm:run && pnpm typeorm:run:certificate",
"migrate:docker": "pnpm typeorm:run:issuer && node_modules/typeorm/cli.js --config dist/js/ormconfig.js migration:run",
"typeorm": "ts-node -r tsconfig-paths/register node_modules/typeorm/cli.js --config ormconfig-dev.ts",
Expand Down
6 changes: 3 additions & 3 deletions apps/drec-api/src/auth/client-jwt.strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ export class ClientJwtStrategy extends PassportStrategy(
}

async validate(request: Request, payload: IJWTPayload) {
// @ts-ignore
const token = request.headers.authorization?.split(' ')[1];
const token = (
request.headers as { authorization?: string }
).authorization?.split(' ')[1];
const user = await this.userService.findByEmail(payload.email);
// @ts-ignore
const publicKey = this.oauthClientService.get(user.api_user_id);
const verifiedData = await this.jwtService.verify(token, {
publicKey: (await publicKey).client_id,
Expand Down
5 changes: 3 additions & 2 deletions apps/drec-api/src/auth/jwt.strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ export class JwtStrategy extends PassportStrategy(Strategy, 'jwt') {
payload: IJWTPayload,
): Promise<IUser | null> {
this.logger.verbose('With in validate');
// @ts-ignore
const token = request.headers.authorization?.split(' ')[1];
const token = (
request.headers as { authorization?: string }
).authorization?.split(' ')[1];
const tokeninvalidate = await this.authService.isTokenBlacklisted(
token,
payload,
Expand Down
17 changes: 7 additions & 10 deletions apps/drec-api/src/guards/WithoutAuthGuard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,16 @@ export class WithoutAuthGuard implements CanActivate {
})
).user;
} else if (request.url.split('/')[3] === 'register') {
const userData = await this.userService.findOne({ role: Role.Admin });
if (
!request.body.api_user_id &&
request.body.api_user_id == undefined &&
(request.body.organizationType === 'Developer' ||
request.body.organizationType === Role.Buyer)
) {
user = await this.userService.findOne({ role: Role.Admin });
user = userData;
} else if (
request.body.api_user_id &&
request.body.api_user_id !=
// @ts-ignore ts(2339)
(await this.userService.findOne({ role: Role.Admin }).api_user_id) &&
request.body.api_user_id != undefined &&
request.body.api_user_id != userData.api_user_id &&
(request.body.organizationType === 'Developer' ||
request.body.organizationType === Role.Buyer)
) {
Expand Down Expand Up @@ -82,11 +81,9 @@ export class WithoutAuthGuard implements CanActivate {
request.body.organizationType === undefined &&
user.role != Role.Admin &&
user.role != Role.ApiUser &&
// @ts-ignore ts(2339)
user.api_user_id !=
// prettier-ignore
// @ts-ignore ts(2339)
((await this.userService.findOne({ role: Role.Admin })) as IUser).api_user_id
((await this.userService.findOne({ role: Role.Admin })) as IUser)
.api_user_id
) {
throw new UnauthorizedException({
statusCode: 401,
Expand Down
2 changes: 0 additions & 2 deletions apps/drec-api/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { startAPI } from '.';
import { Logger } from '@nestjs/common';

// @ts-ignore
process.setMaxListeners(0);

const logger = new Logger();

// @ts-ignore
process.on('warning', (e) => {
logger.warn('warning inside main.ts');
logger.warn(e.stack);
Expand Down
1 change: 0 additions & 1 deletion apps/drec-api/src/models/LoggedInUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export class LoggedInUser implements ILoggedInUser {
this.blockchainAccountAddress = user.organization?.blockchainAccountAddress;
this.role = user.role;
this.permissions = user.permissions;
// @ts-ignore
this.api_user_id = user.api_user_id;
}

Expand Down
9 changes: 8 additions & 1 deletion apps/drec-api/src/models/User.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { IEmailConfirmation, IFullOrganization } from '.';
import { Role, UserStatus, PermissionString } from '../utils/enums';
import {
Role,
UserStatus,
PermissionString,
UserPermissionStatus,
} from '../utils/enums';
import { IModulePermissionsConfig } from './ACLModulesPermission';
export interface IUserProperties {
id: number;
Expand All @@ -13,6 +18,8 @@ export interface IUserProperties {
role: Role;
roleId?: number;
permissions?: PermissionString;
api_user_id?: string;
permission_status?: UserPermissionStatus;
}

export interface IUserSeed extends IUser {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,35 +102,41 @@ describe('CertificateLogService', () => {
it('should create CSV file and send it as response', async () => {
const mockData: CheckCertificateIssueDateLogForDeviceEntity[] = [
{
id: 1,
certificate_issuance_startdate: new Date('2023-11-06T12:48:18.405Z'),
certificate_issuance_enddate: new Date('2023-11-10T04:15:58.000Z'),
readvalue_watthour: 10000,
certificateTransactionUID: '14f8bcd3-095b-4659-90d8-bbc7523d14b4',
// @ts-ignore
reservation_name: 'secondreservation',
externalId: 'Ext2',
blockchainCertificateId: 3,
},
groupId: 2,
status: 'Active',
ongoing_start_date: '2023-11-06T12:48:18.405Z',
ongoing_end_date: '2023-11-10T04:15:58.000Z',
} as CheckCertificateIssueDateLogForDeviceEntity,
{
id: 2,
certificate_issuance_startdate: new Date('2023-11-06T12:48:18.405Z'),
certificate_issuance_enddate: new Date('2023-11-09T04:15:58.000Z'),
readvalue_watthour: 10000,
certificateTransactionUID: '37aa312a-405d-4e37-97f3-8af06a0b1e10',
// @ts-ignore
reservation_name: 'secondreservation',
externalId: 'Ext2',
blockchainCertificateId: 2,
},
groupId: 3,
status: 'Active',
ongoing_start_date: '2023-11-06T12:48:18.405Z',
ongoing_end_date: '2023-11-10T04:15:58.000Z',
} as CheckCertificateIssueDateLogForDeviceEntity,
{
id: 3,
certificate_issuance_startdate: new Date('2022-11-26T11:01:00.000Z'),
certificate_issuance_enddate: new Date('2023-11-06T08:27:44.000Z'),
readvalue_watthour: 10000,
certificateTransactionUID: '770d39fd-fbb3-4eb9-82df-260a740b5151',
// @ts-ignore
reservation_name: 'secondreservation',
externalId: 'Ext2',
blockchainCertificateId: 1,
},
groupId: 4,
status: 'Pending',
ongoing_start_date: '2023-11-06T12:48:18.405Z',
ongoing_end_date: '2023-11-10T04:15:58.000Z',
} as CheckCertificateIssueDateLogForDeviceEntity,
];

jest
Expand Down Expand Up @@ -175,35 +181,41 @@ describe('CertificateLogService', () => {

const expectedLogs: CheckCertificateIssueDateLogForDeviceEntity[] = [
{
id: 1,
groupId: 2,
certificate_issuance_startdate: new Date('2023-11-06T12:48:18.405Z'),
certificate_issuance_enddate: new Date('2023-11-10T04:15:58.000Z'),
readvalue_watthour: 10000,
certificateTransactionUID: '14f8bcd3-095b-4659-90d8-bbc7523d14b4',
// @ts-ignore
reservation_name: 'secondreservation',
externalId: 'Ext2',
blockchainCertificateId: 3,
},
status: 'Active',
ongoing_start_date: '2023-11-06T12:48:18.405Z',
ongoing_end_date: '2023-11-10T04:15:58.000Z',
} as CheckCertificateIssueDateLogForDeviceEntity,
{
id: 2,
groupId: 3,
certificate_issuance_startdate: new Date('2023-11-06T12:48:18.405Z'),
certificate_issuance_enddate: new Date('2023-11-09T04:15:58.000Z'),
readvalue_watthour: 10000,
certificateTransactionUID: '37aa312a-405d-4e37-97f3-8af06a0b1e10',
// @ts-ignore
reservation_name: 'secondreservation',
externalId: 'Ext2',
blockchainCertificateId: 2,
},
status: 'pending',
ongoing_start_date: '2023-11-06T12:48:18.405Z',
ongoing_end_date: '2023-11-09T04:15:58.000Z',
} as CheckCertificateIssueDateLogForDeviceEntity,
{
id: 3,
groupId: 4,
certificate_issuance_startdate: new Date('2022-11-26T11:01:00.000Z'),
certificate_issuance_enddate: new Date('2023-11-06T08:27:44.000Z'),
readvalue_watthour: 10000,
certificateTransactionUID: '770d39fd-fbb3-4eb9-82df-260a740b5151',
// @ts-ignore
reservation_name: 'secondreservation',
externalId: 'Ext2',
blockchainCertificateId: 1,
},
status: 'pending',
ongoing_start_date: '2023-11-06T12:48:18.405Z',
ongoing_end_date: '2023-11-09T04:15:58.000Z',
} as CheckCertificateIssueDateLogForDeviceEntity,
];

jest
Expand Down Expand Up @@ -268,8 +280,10 @@ describe('CertificateLogService', () => {
},
ownerId: '',
hasOrganization: false,
// @ts-ignore
hasPermission: true,
permissions: PermissionString.Write,
hasPermission: function (...permissions: PermissionString[]): boolean {
throw new Error('Function not implemented.');
},
api_user_id: 'apiuserId',
};
const filterDto: FilterDTO = {
Expand Down Expand Up @@ -326,7 +340,6 @@ describe('CertificateLogService', () => {
certificate_issuance_enddate: new Date('2023-11-10T04:15:58.000Z'),
readvalue_watthour: 10000,
certificateTransactionUID: '14f8bcd3-095b-4659-90d8-bbc7523d14b4',
// @ts-ignore
reservation_name: 'secondreservation',
externalId: 'Ext2',
blockchainCertificateId: 3,
Expand All @@ -338,7 +351,6 @@ describe('CertificateLogService', () => {
certificate_issuance_enddate: new Date('2023-11-09T04:15:58.000Z'),
readvalue_watthour: 10000,
certificateTransactionUID: '37aa312a-405d-4e37-97f3-8af06a0b1e10',
// @ts-ignore
reservation_name: 'secondreservation',
externalId: 'Ext2',
blockchainCertificateId: 2,
Expand All @@ -350,7 +362,6 @@ describe('CertificateLogService', () => {
certificate_issuance_enddate: new Date('2023-11-06T08:27:44.000Z'),
readvalue_watthour: 10000,
certificateTransactionUID: '770d39fd-fbb3-4eb9-82df-260a740b5151',
// @ts-ignore
reservation_name: 'secondreservation',
externalId: 'Ext2',
blockchainCertificateId: 1,
Expand Down Expand Up @@ -401,8 +412,10 @@ describe('CertificateLogService', () => {
},
ownerId: '',
hasOrganization: false,
// @ts-ignore
hasPermission: true,
permissions: PermissionString.Write,
hasPermission: function (...permissions: PermissionString[]): boolean {
throw new Error('Function not implemented.');
},
api_user_id: 'apiuserId',
};
const filterDto: FilterDTO = {
Expand Down Expand Up @@ -459,7 +472,6 @@ describe('CertificateLogService', () => {
certificate_issuance_enddate: new Date('2023-11-10T04:15:58.000Z'),
readvalue_watthour: 10000,
certificateTransactionUID: '14f8bcd3-095b-4659-90d8-bbc7523d14b4',
//@ts-ignore
reservation_name: 'secondreservation',
externalId: 'Ext2',
blockchainCertificateId: 3,
Expand All @@ -471,7 +483,6 @@ describe('CertificateLogService', () => {
certificate_issuance_enddate: new Date('2023-11-09T04:15:58.000Z'),
readvalue_watthour: 10000,
certificateTransactionUID: '37aa312a-405d-4e37-97f3-8af06a0b1e10',
//@ts-ignore
reservation_name: 'secondreservation',
externalId: 'Ext2',
blockchainCertificateId: 2,
Expand All @@ -483,7 +494,6 @@ describe('CertificateLogService', () => {
certificate_issuance_enddate: new Date('2023-11-06T08:27:44.000Z'),
readvalue_watthour: 10000,
certificateTransactionUID: '770d39fd-fbb3-4eb9-82df-260a740b5151',
//@ts-ignore
reservation_name: 'secondreservation',
externalId: 'Ext2',
blockchainCertificateId: 1,
Expand Down Expand Up @@ -523,8 +533,10 @@ describe('CertificateLogService', () => {
},
ownerId: '',
hasOrganization: false,
// @ts-ignore
hasPermission: true,
permissions: PermissionString.Write,
hasPermission: function (...permissions: PermissionString[]): boolean {
throw new Error('Function not implemented.');
},
api_user_id: 'apiuserId',
};
const filterDto: FilterDTO = {
Expand Down
Loading

0 comments on commit adbb65d

Please sign in to comment.