Skip to content

Commit

Permalink
fix: linting, refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
MrMaz committed Jun 4, 2024
1 parent dc28cdb commit 2a96218
Show file tree
Hide file tree
Showing 26 changed files with 1,682 additions and 766 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci-pr-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ jobs:

- name: Install and build
run: yarn --frozen-lockfile
- name: Linting
run: yarn lint
- name: Unit tests
run: yarn test:ci
- name: Save the PR number in an artifact
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"devDependencies": {
"@commitlint/cli": "^16.1.0",
"@commitlint/config-conventional": "^16.0.0",
"@compodoc/compodoc": "^1.1.18",
"@compodoc/compodoc": "^1.1.25",
"@concepta/eslint-config": "^1.1.4",
"@concepta/prettier-config": "^1.1.4",
"@darraghor/eslint-plugin-nestjs-typed": "^3.20.5",
Expand All @@ -30,7 +30,7 @@
"eslint": "^8.6.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-jsdoc": "^37.6.1",
"eslint-plugin-jsdoc": "^48.2.7",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^4.0.0",
"husky": "^7.0.4",
Expand Down
19 changes: 10 additions & 9 deletions packages/nestjs-cache/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@concepta/nestjs-cache",
"version": "4.0.0-alpha.42",
"version": "4.0.0-alpha.44",
"description": "Rockets NestJS User",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand All @@ -12,14 +12,15 @@
"dist/**/!(*.spec|*.e2e-spec|*.fixture).{js,d.ts}"
],
"dependencies": {
"@concepta/nestjs-access-control": "^4.0.0-alpha.42",
"@concepta/nestjs-common": "^4.0.0-alpha.42",
"@concepta/nestjs-core": "^4.0.0-alpha.42",
"@concepta/nestjs-crud": "^4.0.0-alpha.42",
"@concepta/nestjs-typeorm-ext": "^4.0.0-alpha.42",
"@concepta/ts-common": "^4.0.0-alpha.42",
"@concepta/ts-core": "^4.0.0-alpha.42",
"@concepta/typeorm-common": "^4.0.0-alpha.42",
"@concepta/nestjs-access-control": "^4.0.0-alpha.44",
"@concepta/nestjs-common": "^4.0.0-alpha.44",
"@concepta/nestjs-core": "^4.0.0-alpha.44",
"@concepta/nestjs-crud": "^4.0.0-alpha.44",
"@concepta/nestjs-exception": "^4.0.0-alpha.44",
"@concepta/nestjs-typeorm-ext": "^4.0.0-alpha.44",
"@concepta/ts-common": "^4.0.0-alpha.44",
"@concepta/ts-core": "^4.0.0-alpha.44",
"@concepta/typeorm-common": "^4.0.0-alpha.44",
"@nestjs/common": "^9.0.0",
"@nestjs/config": "^2.2.0",
"@nestjs/swagger": "^6.0.0",
Expand Down
7 changes: 3 additions & 4 deletions packages/nestjs-cache/src/__fixtures__/app.module.fixture.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { TypeOrmExtModule } from '@concepta/nestjs-typeorm-ext';
import { Module } from '@nestjs/common';
import { TypeOrmExtModule } from '@concepta/nestjs-typeorm-ext';
import { CrudModule } from '@concepta/nestjs-crud';

import { CacheModule } from '../cache.module';
import { UserEntityFixture } from './entities/user-entity.fixture';
import { UserCacheEntityFixture } from './entities/user-cache-entity.fixture';
import { CrudModule } from '@concepta/nestjs-crud';

@Module({
imports: [
Expand All @@ -29,5 +29,4 @@ import { CrudModule } from '@concepta/nestjs-crud';
CrudModule.forRoot({}),
],
})
export class AppModuleFixture { }

export class AppModuleFixture {}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

import Faker from '@faker-js/faker';
import { Factory } from '@concepta/typeorm-seeding';
import { UserCacheEntityFixture } from '../entities/user-cache-entity.fixture';
import Faker from '@faker-js/faker';

export class UserCacheFactoryFixture extends Factory<UserCacheEntityFixture> {
protected options = {
Expand Down
4 changes: 4 additions & 0 deletions packages/nestjs-cache/src/cache.constants.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
export const CACHE_MODULE_SETTINGS_TOKEN = 'CACHE_MODULE_SETTINGS_TOKEN';

export const CACHE_MODULE_REPOSITORIES_TOKEN =
'CACHE_MODULE_REPOSITORIES_TOKEN';

export const CACHE_MODULE_CRUD_SERVICES_TOKEN =
'CACHE_MODULE_CRUD_SERVICES_TOKEN';

export const CACHE_MODULE_DEFAULT_SETTINGS_TOKEN =
'CACHE_MODULE_DEFAULT_SETTINGS_TOKEN';

export const CACHE_MODULE_CACHE_ENTITY_KEY = 'cache';
1 change: 1 addition & 0 deletions packages/nestjs-cache/src/cache.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { randomUUID } from 'crypto';
import Faker from '@faker-js/faker';
import { Factory } from '@concepta/typeorm-seeding';
import { CacheInterface } from '@concepta/ts-common';

/**
* Cache factory
*/
Expand Down
4 changes: 2 additions & 2 deletions packages/nestjs-cache/src/cache.types.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CacheResource } from './cache.types';

describe('Org Types', () => {
describe('OrgResource enum', () => {
describe('Cache Types', () => {
describe('Cache enum', () => {
it('should match', async () => {
expect(CacheResource.One).toEqual('cache');
expect(CacheResource.Many).toEqual('cache-list');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
import { CacheCreatableInterface } from '@concepta/ts-common';
import { SeedingSource } from '@concepta/typeorm-seeding';
import assert from 'assert';
import supertest from 'supertest';
import { INestApplication } from '@nestjs/common';
import { Test, TestingModule } from '@nestjs/testing';
import { getDataSourceToken } from '@nestjs/typeorm';
import assert from 'assert';
import supertest from 'supertest';
import { Repository } from 'typeorm';

import { CACHE_MODULE_REPOSITORIES_TOKEN } from '../cache.constants';
import { CacheCreatableInterface } from '@concepta/ts-common';
import { SeedingSource } from '@concepta/typeorm-seeding';

import { CacheFactory } from '../cache.factory';
import { CacheSeeder } from '../cache.seeder';

import { AppModuleFixture } from '../__fixtures__/app.module.fixture';

import { UserCacheEntityFixture } from '../__fixtures__/entities/user-cache-entity.fixture';
import { UserEntityFixture } from '../__fixtures__/entities/user-entity.fixture';
import { UserCacheFactoryFixture } from '../__fixtures__/factories/user-cache.factory.fixture';
Expand Down Expand Up @@ -134,7 +130,7 @@ describe('CacheAssignmentController (e2e)', () => {
});
});

it.only('POST /cache/user Duplicated', async () => {
it('POST /cache/user Duplicated', async () => {
const payload: CacheCreatableInterface = {
key: 'dashboard-1',
type: 'filter',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Inject, Param } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';
import {
AccessControlCreateOne,
AccessControlDeleteOne,
Expand All @@ -22,9 +24,6 @@ import {
CacheUpdatableInterface,
} from '@concepta/ts-common';
import { ReferenceAssignment } from '@concepta/ts-core';
import { Inject, Param } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';
import ms from 'ms';
import {
CACHE_MODULE_CRUD_SERVICES_TOKEN,
CACHE_MODULE_SETTINGS_TOKEN,
Expand All @@ -34,7 +33,7 @@ import { CachePaginatedDto } from '../dto/cache-paginated.dto';
import { CacheUpdateDto } from '../dto/cache-update.dto';
import { CacheDto } from '../dto/cache.dto';
import { CacheAssignmentNotFoundException } from '../exceptions/cache-assignment-not-found.exception';
import { EntityNotFoundException } from '../exceptions/entity-not-found.exception';
import { CacheEntityNotFoundException } from '../exceptions/cache-entity-not-found.exception';
import { CacheSettingsInterface } from '../interfaces/cache-settings.interface';
import { CacheCrudService } from '../services/cache-crud.service';
import getExpirationDate from '../utils/get-expiration-date.util';
Expand Down Expand Up @@ -191,7 +190,7 @@ export class CacheCrudController
return this.allCrudServices[entityKey];
} else {
// bad entity key
throw new EntityNotFoundException(entityKey);
throw new CacheEntityNotFoundException(entityKey);
}
} else {
// bad assignment
Expand Down
7 changes: 3 additions & 4 deletions packages/nestjs-cache/src/dto/cache-create.dto.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CacheCreatableInterface } from '@concepta/ts-common';
import { PickType } from '@nestjs/swagger';
import { Exclude } from 'class-transformer';
import { PickType } from '@nestjs/swagger';
import { CacheCreatableInterface } from '@concepta/ts-common';
import { CacheDto } from './cache.dto';
/**
* Cache Create DTO
Expand All @@ -14,5 +14,4 @@ export class CacheCreateDto
'expiresIn',
'assignee',
] as const)
implements CacheCreatableInterface
{}
implements CacheCreatableInterface {}
5 changes: 3 additions & 2 deletions packages/nestjs-cache/src/dto/cache-paginated.dto.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Exclude, Expose, Type } from 'class-transformer';
import { CacheInterface } from '@concepta/ts-common';
import { ApiProperty } from '@nestjs/swagger';
import { CacheInterface } from '@concepta/ts-common';
import { CrudResponsePaginatedDto } from '@concepta/nestjs-crud';
import { CacheDto } from './cache.dto';

/**
* Org paginated DTO
* Cache paginated DTO
*/
@Exclude()
export class CachePaginatedDto extends CrudResponsePaginatedDto<CacheInterface> {
Expand Down
5 changes: 3 additions & 2 deletions packages/nestjs-cache/src/dto/cache-update.dto.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { CacheUpdatableInterface } from '@concepta/ts-common';
import { PickType } from '@nestjs/swagger';
import { Exclude } from 'class-transformer';
import { PickType } from '@nestjs/swagger';
import { CacheUpdatableInterface } from '@concepta/ts-common';
import { CacheDto } from './cache.dto';

/**
* Cache Create DTO
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Column, Index, Unique } from 'typeorm';
import { Column, Index } from 'typeorm';
import { ReferenceIdInterface } from '@concepta/ts-core';
import { CacheInterface } from '@concepta/ts-common';
import { CommonPostgresEntity } from '@concepta/typeorm-common';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CacheAssignmentNotFoundException } from "./cache-assignment-not-found.exception";
import { CacheAssignmentNotFoundException } from './cache-assignment-not-found.exception';

describe('AssignmentNotFoundException', () => {
it('should create an instance with default message', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
import { format } from 'util';
import { ExceptionInterface } from '@concepta/ts-core';
import { HttpStatus } from '@nestjs/common';
import { RuntimeException } from '@concepta/nestjs-exception';

export class CacheAssignmentNotFoundException
extends Error
implements ExceptionInterface
{
errorCode = 'CACHE_ASSIGNMENT_NOT_FOUND_ERROR';

context: {
export class CacheAssignmentNotFoundException extends RuntimeException {
context: RuntimeException['context'] & {
assignmentName: string;
};

constructor(
assignmentName: string,
message = 'Assignment %s was not registered to be used.',
) {
super(format(message, assignmentName));
super({
message,
messageParams: [assignmentName],
httpStatus: HttpStatus.NOT_FOUND,
});

this.errorCode = 'CACHE_ASSIGNMENT_NOT_FOUND_ERROR';

this.context = {
...super.context,
assignmentName,
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import { EntityNotFoundException } from './entity-not-found.exception';
import { CacheEntityNotFoundException } from './cache-entity-not-found.exception';

describe(EntityNotFoundException.name, () => {
describe(CacheEntityNotFoundException.name, () => {
it('should create an instance of EntityNotFoundException', () => {
const exception = new EntityNotFoundException('TestEntity');
expect(exception).toBeInstanceOf(EntityNotFoundException);
const exception = new CacheEntityNotFoundException('TestEntity');
expect(exception).toBeInstanceOf(CacheEntityNotFoundException);
});

it('should have the correct error message', () => {
const exception = new EntityNotFoundException('TestEntity');
const exception = new CacheEntityNotFoundException('TestEntity');
expect(exception.message).toBe(
'Entity TestEntity was not registered to be used.',
);
});

it('should have the correct context', () => {
const exception = new EntityNotFoundException('TestEntity');
const exception = new CacheEntityNotFoundException('TestEntity');
expect(exception.context).toEqual({ entityName: 'TestEntity' });
});

it('should have the correct error code', () => {
const exception = new EntityNotFoundException('TestEntity');
const exception = new CacheEntityNotFoundException('TestEntity');
expect(exception.errorCode).toBe('CACHE_ENTITY_NOT_FOUND_ERROR');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { RuntimeException } from '@concepta/nestjs-exception';

export class CacheEntityNotFoundException extends RuntimeException {
context: RuntimeException['context'] & {
entityName: string;
};

constructor(
entityName: string,
message = 'Entity %s was not registered to be used.',
) {
super({
message,
messageParams: [entityName],
});

this.errorCode = 'CACHE_ENTITY_NOT_FOUND_ERROR';

this.context = {
...super.context,
entityName,
};
}
}

This file was deleted.

This file was deleted.

Loading

0 comments on commit 2a96218

Please sign in to comment.