Skip to content

Commit

Permalink
Merge pull request #4 from knovator/APIs-project_template
Browse files Browse the repository at this point in the history
APIs for Project & Template
  • Loading branch information
chavda-bhavik authored Oct 5, 2022
2 parents c720804 + 2786c9d commit 1da2cb5
Show file tree
Hide file tree
Showing 21 changed files with 138 additions and 12 deletions.
1 change: 1 addition & 0 deletions apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
},
"dependencies": {
"@impler/dal": "workspace:^1.0.0",
"@impler/shared": "workspace:^1.0.0",
"@nestjs/common": "^9.1.2",
"@nestjs/core": "^9.1.2",
"@nestjs/platform-express": "^9.1.2",
Expand Down
14 changes: 12 additions & 2 deletions apps/api/src/app/project/dtos/create-project-request.dto.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsDefined, IsString, Validate } from 'class-validator';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { IsDefined, IsOptional, IsString, Validate } from 'class-validator';
import { Transform } from 'class-transformer';
import { changeToCode } from '@impler/shared';
import { UniqueValidator } from '../../shared/framework/IsUniqueValidator';

export class CreateProjectRequestDto {
Expand All @@ -18,5 +20,13 @@ export class CreateProjectRequestDto {
@Validate(UniqueValidator, ['Project', 'code'], {
message: 'Code is already taken',
})
@Transform((value) => changeToCode(value.value))
code: string;

@ApiPropertyOptional({
description: 'Name of authentication header to sent along the request',
})
@IsString()
@IsOptional()
authHeaderName: string;
}
9 changes: 8 additions & 1 deletion apps/api/src/app/project/dtos/project-response.dto.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { IsDefined, IsString } from 'class-validator';
import { IsDefined, IsOptional, IsString } from 'class-validator';

export class ProjectResponseDto {
@ApiPropertyOptional({
Expand All @@ -22,4 +22,11 @@ export class ProjectResponseDto {
@IsString()
@IsDefined()
code: string;

@ApiPropertyOptional({
description: 'Name of authentication header to sent along the request',
})
@IsString()
@IsOptional()
authHeaderName?: string;
}
15 changes: 11 additions & 4 deletions apps/api/src/app/project/dtos/update-project-request.dto.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsDefined, IsString } from 'class-validator';
import { ApiPropertyOptional } from '@nestjs/swagger';
import { IsOptional, IsString } from 'class-validator';

export class UpdateProjectRequestDto {
@ApiProperty({
@ApiPropertyOptional({
description: 'Name of the project',
})
@IsString()
@IsDefined()
@IsOptional()
name: string;

@ApiPropertyOptional({
description: 'Name of authentication header to sent along the request',
})
@IsString()
@IsOptional()
authHeaderName: string;
}
3 changes: 2 additions & 1 deletion apps/api/src/app/project/project.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export class ProjectController {
CreateProjectCommand.create({
code: body.code,
name: body.name,
authHeaderName: body.authHeaderName,
})
);
}
Expand All @@ -61,7 +62,7 @@ export class ProjectController {
@Param('projectId', ValidateMongoId) projectId: string
): Promise<ProjectResponseDto> {
const document = await this.updateProjectUsecase.execute(
UpdateProjectCommand.create({ name: body.name }),
UpdateProjectCommand.create({ name: body.name, authHeaderName: body.authHeaderName }),
projectId
);
if (!document) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IsDefined, IsString } from 'class-validator';
import { IsDefined, IsOptional, IsString } from 'class-validator';
import { BaseCommand } from '../../../shared/commands/base.command';

export class CreateProjectCommand extends BaseCommand {
Expand All @@ -9,4 +9,8 @@ export class CreateProjectCommand extends BaseCommand {
@IsDefined()
@IsString()
code: string;

@IsOptional()
@IsString()
authHeaderName: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export class GetProjects {
_id: project._id,
name: project.name,
code: project.code,
authHeaderName: project.authHeaderName,
};
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { IsDefined, IsString } from 'class-validator';
import { IsOptional, IsString } from 'class-validator';
import { BaseCommand } from '../../../shared/commands/base.command';

export class UpdateProjectCommand extends BaseCommand {
@IsDefined()
@IsOptional()
@IsString()
name: string;

@IsOptional()
@IsString()
authHeaderName: string;
}
3 changes: 3 additions & 0 deletions apps/api/src/app/template/dtos/create-template-request.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { ApiProperty } from '@nestjs/swagger';
import { Transform } from 'class-transformer';
import { changeToCode } from '@impler/shared';
import { IsDefined, IsString, Validate, IsNumber } from 'class-validator';
import { UniqueValidator } from '../../shared/framework/IsUniqueValidator';

Expand All @@ -18,6 +20,7 @@ export class CreateTemplateRequestDto {
@Validate(UniqueValidator, ['Template', 'code'], {
message: 'Code is already taken',
})
@Transform((value) => changeToCode(value.value))
code: string;

@ApiProperty({
Expand Down
2 changes: 2 additions & 0 deletions libs/dal/src/repositories/project/project.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ export class ProjectEntity {
name: string;

code: string;

authHeaderName: string;
}
3 changes: 3 additions & 0 deletions libs/dal/src/repositories/project/project.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ const projectSchema = new Schema(
code: {
type: Schema.Types.String,
},
authHeaderName: {
type: Schema.Types.String,
},
},
{ ...schemaOptions }
);
Expand Down
1 change: 1 addition & 0 deletions libs/shared/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
3 changes: 3 additions & 0 deletions libs/shared/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
extends: ['../../.eslintrc.js'],
};
6 changes: 6 additions & 0 deletions libs/shared/nodemon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"watch": ["src"],
"ext": "ts",
"ignore": ["src/**/*.spec.ts"],
"exec": "ts-node -r tsconfig-paths/register src/main.app.ts"
}
35 changes: 35 additions & 0 deletions libs/shared/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "@impler/shared",
"version": "1.0.0",
"description": "",
"private": true,
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"start": "npm run start:dev",
"afterinstall": "pnpm build",
"prebuild": "rimraf dist",
"build": "cross-env node_modules/.bin/tsc -p tsconfig.build.json",
"build:watch": "cross-env node_modules/.bin/tsc -p tsconfig.build.json -w --preserveWatchOutput",
"start:dev": "pnpm build:watch",
"precommit": "lint-staged",
"lint": "eslint src",
"lint:fix": "pnpm lint -- --fix",
"test": "",
"test:watch": ""
},
"devDependencies": {
"@types/node": "^18.7.18",
"typescript": "^4.8.3"
},
"dependencies": {
"rimraf": "^3.0.2"
},
"lint-staged": {
"*.{js,jsx,ts,tsx}": ["prettier --ignore-path .eslintignore --write"],
"{*.json,.{babelrc,eslintrc,prettierrc,stylelintrc}}": [
"prettier --ignore-path .eslintignore --parser json --write"
],
"*.{html,md,yml}": ["prettier --ignore-path .eslintignore --single-quote --write"]
}
}
1 change: 1 addition & 0 deletions libs/shared/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './utils/helpers';
5 changes: 5 additions & 0 deletions libs/shared/src/utils/helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const changeToCode = (str = '') =>
str
?.replace(/[^\s\w]/gi, '')
?.toUpperCase()
?.replace(/ /g, '_');
12 changes: 12 additions & 0 deletions libs/shared/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"declaration": true,
"outDir": "./dist",
"rootDir": "./src",
"types": ["node"]
},
"include": ["src/**/*"]
}
6 changes: 6 additions & 0 deletions libs/shared/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"types": ["node"]
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"prebuild": "nx run-many --target=prebuild --all",
"build": "nx run-many --target=build --all",
"build:api": "nx build @impler/api",
"build:dal": "nx build @impler/dal"
"build:dal": "nx build @impler/dal",
"build:shared": "nx build @impler/shared"
},
"keywords": [
"data-import",
Expand Down
13 changes: 13 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1da2cb5

Please sign in to comment.