Template
feat : concept creation
This commit is contained in:
Vendored
+4
@@ -9,5 +9,9 @@
|
|||||||
"eslint.useFlatConfig": true,
|
"eslint.useFlatConfig": true,
|
||||||
"[json]": {
|
"[json]": {
|
||||||
"editor.defaultFormatter": "vscode.json-language-features"
|
"editor.defaultFormatter": "vscode.json-language-features"
|
||||||
|
},
|
||||||
|
"files.exclude": {
|
||||||
|
"**/dist": true,
|
||||||
|
"**/node_modules": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-1
@@ -1,3 +1,6 @@
|
|||||||
|
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
||||||
|
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
||||||
|
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
||||||
import typescriptEslintEslintPlugin from '@typescript-eslint/eslint-plugin';
|
import typescriptEslintEslintPlugin from '@typescript-eslint/eslint-plugin';
|
||||||
import globals from 'globals';
|
import globals from 'globals';
|
||||||
import tsParser from '@typescript-eslint/parser';
|
import tsParser from '@typescript-eslint/parser';
|
||||||
@@ -39,7 +42,7 @@ export default [
|
|||||||
|
|
||||||
parserOptions: {
|
parserOptions: {
|
||||||
project: 'tsconfig.json',
|
project: 'tsconfig.json',
|
||||||
tsconfigRootDir: '/home/legonzaur/Documents/code/concept/back',
|
tsconfigRootDir: __dirname,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
+1
-1
Submodule events updated: 1473c5c132...a99853f417
@@ -23,7 +23,10 @@ import { ConceptService } from './concept.service';
|
|||||||
import { Concept } from './entities/concept.entity';
|
import { Concept } from './entities/concept.entity';
|
||||||
import { ConceptPipe } from './concept.pipe';
|
import { ConceptPipe } from './concept.pipe';
|
||||||
import { ConceptRecieveDTO } from './dto/conceptrecieve.dto';
|
import { ConceptRecieveDTO } from './dto/conceptrecieve.dto';
|
||||||
import { ConceptResponseDTO } from 'events/dto/conceptresponse.dto';
|
import {
|
||||||
|
ConceptResponseDTO,
|
||||||
|
ConceptTypeResponseDTO,
|
||||||
|
} from 'events/dto/conceptresponse.dto';
|
||||||
|
|
||||||
@ApiTags('concepts')
|
@ApiTags('concepts')
|
||||||
@Controller('concepts')
|
@Controller('concepts')
|
||||||
@@ -72,6 +75,14 @@ export class ConceptController {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Get('/types')
|
||||||
|
@ApiOperation({ summary: 'List concept types' })
|
||||||
|
async readTypes() {
|
||||||
|
return (await this.conceptService.listTypes()).map(
|
||||||
|
(w) => new ConceptTypeResponseDTO(w),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@Get('/all')
|
@Get('/all')
|
||||||
@ApiOperation({ summary: 'List all concepts' })
|
@ApiOperation({ summary: 'List all concepts' })
|
||||||
async readAll() {
|
async readAll() {
|
||||||
|
|||||||
@@ -6,9 +6,10 @@ import { UsersModule } from 'src/users/users.module';
|
|||||||
import { Concept } from './entities/concept.entity';
|
import { Concept } from './entities/concept.entity';
|
||||||
import { ConceptService } from './concept.service';
|
import { ConceptService } from './concept.service';
|
||||||
import { ConceptController } from './concept.controller';
|
import { ConceptController } from './concept.controller';
|
||||||
|
import { ConceptType } from './entities/concepttype.entity';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [UsersModule, TypeOrmModule.forFeature([Concept])],
|
imports: [UsersModule, TypeOrmModule.forFeature([Concept, ConceptType])],
|
||||||
providers: [ConceptService],
|
providers: [ConceptService],
|
||||||
controllers: [ConceptController],
|
controllers: [ConceptController],
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"id": 1,
|
||||||
|
"value": "type"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 2,
|
||||||
|
"value": "subtype"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 3,
|
||||||
|
"value": "material"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 4,
|
||||||
|
"value": "shape"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 5,
|
||||||
|
"value": "color"
|
||||||
|
}
|
||||||
|
]
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
|
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
|
||||||
import { InjectRepository } from '@nestjs/typeorm';
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
import { Repository } from 'typeorm';
|
import { DeepPartial, Repository } from 'typeorm';
|
||||||
|
|
||||||
import { EventEmitter2 } from '@nestjs/event-emitter';
|
import { EventEmitter2 } from '@nestjs/event-emitter';
|
||||||
import { Concept } from './entities/concept.entity';
|
import { Concept } from './entities/concept.entity';
|
||||||
@@ -10,14 +10,21 @@ import {
|
|||||||
ConceptEnableEvent,
|
ConceptEnableEvent,
|
||||||
ConceptDisableEvent,
|
ConceptDisableEvent,
|
||||||
} from 'events/concept.events';
|
} from 'events/concept.events';
|
||||||
|
import { ConceptType } from './entities/concepttype.entity';
|
||||||
|
|
||||||
|
import typeSeeds from './concept.seed.json';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ConceptService {
|
export class ConceptService {
|
||||||
sse_prefix = 'sse.concept';
|
sse_prefix = 'sse.concept';
|
||||||
constructor(
|
constructor(
|
||||||
@InjectRepository(Concept) private conceptRepository: Repository<Concept>,
|
@InjectRepository(Concept) private conceptRepository: Repository<Concept>,
|
||||||
|
@InjectRepository(ConceptType)
|
||||||
|
private conceptTypeRepository: Repository<ConceptType>,
|
||||||
private eventEmitter: EventEmitter2,
|
private eventEmitter: EventEmitter2,
|
||||||
) {}
|
) {
|
||||||
|
void conceptTypeRepository.save(typeSeeds as DeepPartial<ConceptType>[]);
|
||||||
|
}
|
||||||
|
|
||||||
async getById(id: number) {
|
async getById(id: number) {
|
||||||
return await this.conceptRepository.findOneBy({ id });
|
return await this.conceptRepository.findOneBy({ id });
|
||||||
@@ -31,7 +38,11 @@ export class ConceptService {
|
|||||||
|
|
||||||
async create(value: string, image: string) {
|
async create(value: string, image: string) {
|
||||||
const concept = this.conceptRepository.create();
|
const concept = this.conceptRepository.create();
|
||||||
|
const conceptType = await this.conceptTypeRepository.findOneByOrFail({
|
||||||
|
id: 1,
|
||||||
|
});
|
||||||
concept.value = value;
|
concept.value = value;
|
||||||
|
concept.type = conceptType;
|
||||||
try {
|
try {
|
||||||
await this.conceptRepository.save(concept);
|
await this.conceptRepository.save(concept);
|
||||||
this.eventEmitter.emit(this.sse_prefix, new ConceptCreateEvent(concept));
|
this.eventEmitter.emit(this.sse_prefix, new ConceptCreateEvent(concept));
|
||||||
@@ -46,6 +57,10 @@ export class ConceptService {
|
|||||||
return concepts;
|
return concepts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async listTypes() {
|
||||||
|
return await this.conceptTypeRepository.find();
|
||||||
|
}
|
||||||
|
|
||||||
async list() {
|
async list() {
|
||||||
const concepts = await this.conceptRepository.find();
|
const concepts = await this.conceptRepository.find();
|
||||||
return concepts;
|
return concepts;
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ export class Concept {
|
|||||||
|
|
||||||
@ManyToOne(() => ConceptType, {
|
@ManyToOne(() => ConceptType, {
|
||||||
eager: true,
|
eager: true,
|
||||||
nullable: true,
|
nullable: false,
|
||||||
onDelete: 'CASCADE',
|
onDelete: 'CASCADE',
|
||||||
})
|
})
|
||||||
type: ConceptType;
|
type: ConceptType;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import {
|
|||||||
Column,
|
Column,
|
||||||
Entity,
|
Entity,
|
||||||
OneToMany,
|
OneToMany,
|
||||||
|
PrimaryColumn,
|
||||||
PrimaryGeneratedColumn,
|
PrimaryGeneratedColumn,
|
||||||
Unique,
|
Unique,
|
||||||
} from 'typeorm';
|
} from 'typeorm';
|
||||||
@@ -10,7 +11,7 @@ import { Concept } from './concept.entity';
|
|||||||
@Entity()
|
@Entity()
|
||||||
@Unique(['value'])
|
@Unique(['value'])
|
||||||
export class ConceptType {
|
export class ConceptType {
|
||||||
@PrimaryGeneratedColumn()
|
@PrimaryColumn()
|
||||||
id: number;
|
id: number;
|
||||||
|
|
||||||
@Column()
|
@Column()
|
||||||
|
|||||||
+2
-1
@@ -12,6 +12,7 @@
|
|||||||
"baseUrl": "./",
|
"baseUrl": "./",
|
||||||
"incremental": true,
|
"incremental": true,
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
"esModuleInterop": true
|
"esModuleInterop": true,
|
||||||
|
"resolveJsonModule": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user