feat : concept creation
This commit is contained in:
Vendored
+4
@@ -9,5 +9,9 @@
|
||||
"eslint.useFlatConfig": true,
|
||||
"[json]": {
|
||||
"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 globals from 'globals';
|
||||
import tsParser from '@typescript-eslint/parser';
|
||||
@@ -39,7 +42,7 @@ export default [
|
||||
|
||||
parserOptions: {
|
||||
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 { ConceptPipe } from './concept.pipe';
|
||||
import { ConceptRecieveDTO } from './dto/conceptrecieve.dto';
|
||||
import { ConceptResponseDTO } from 'events/dto/conceptresponse.dto';
|
||||
import {
|
||||
ConceptResponseDTO,
|
||||
ConceptTypeResponseDTO,
|
||||
} from 'events/dto/conceptresponse.dto';
|
||||
|
||||
@ApiTags('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')
|
||||
@ApiOperation({ summary: 'List all concepts' })
|
||||
async readAll() {
|
||||
|
||||
@@ -6,9 +6,10 @@ import { UsersModule } from 'src/users/users.module';
|
||||
import { Concept } from './entities/concept.entity';
|
||||
import { ConceptService } from './concept.service';
|
||||
import { ConceptController } from './concept.controller';
|
||||
import { ConceptType } from './entities/concepttype.entity';
|
||||
|
||||
@Module({
|
||||
imports: [UsersModule, TypeOrmModule.forFeature([Concept])],
|
||||
imports: [UsersModule, TypeOrmModule.forFeature([Concept, ConceptType])],
|
||||
providers: [ConceptService],
|
||||
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 { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { DeepPartial, Repository } from 'typeorm';
|
||||
|
||||
import { EventEmitter2 } from '@nestjs/event-emitter';
|
||||
import { Concept } from './entities/concept.entity';
|
||||
@@ -10,14 +10,21 @@ import {
|
||||
ConceptEnableEvent,
|
||||
ConceptDisableEvent,
|
||||
} from 'events/concept.events';
|
||||
import { ConceptType } from './entities/concepttype.entity';
|
||||
|
||||
import typeSeeds from './concept.seed.json';
|
||||
|
||||
@Injectable()
|
||||
export class ConceptService {
|
||||
sse_prefix = 'sse.concept';
|
||||
constructor(
|
||||
@InjectRepository(Concept) private conceptRepository: Repository<Concept>,
|
||||
@InjectRepository(ConceptType)
|
||||
private conceptTypeRepository: Repository<ConceptType>,
|
||||
private eventEmitter: EventEmitter2,
|
||||
) {}
|
||||
) {
|
||||
void conceptTypeRepository.save(typeSeeds as DeepPartial<ConceptType>[]);
|
||||
}
|
||||
|
||||
async getById(id: number) {
|
||||
return await this.conceptRepository.findOneBy({ id });
|
||||
@@ -31,7 +38,11 @@ export class ConceptService {
|
||||
|
||||
async create(value: string, image: string) {
|
||||
const concept = this.conceptRepository.create();
|
||||
const conceptType = await this.conceptTypeRepository.findOneByOrFail({
|
||||
id: 1,
|
||||
});
|
||||
concept.value = value;
|
||||
concept.type = conceptType;
|
||||
try {
|
||||
await this.conceptRepository.save(concept);
|
||||
this.eventEmitter.emit(this.sse_prefix, new ConceptCreateEvent(concept));
|
||||
@@ -46,6 +57,10 @@ export class ConceptService {
|
||||
return concepts;
|
||||
}
|
||||
|
||||
async listTypes() {
|
||||
return await this.conceptTypeRepository.find();
|
||||
}
|
||||
|
||||
async list() {
|
||||
const concepts = await this.conceptRepository.find();
|
||||
return concepts;
|
||||
|
||||
@@ -21,7 +21,7 @@ export class Concept {
|
||||
|
||||
@ManyToOne(() => ConceptType, {
|
||||
eager: true,
|
||||
nullable: true,
|
||||
nullable: false,
|
||||
onDelete: 'CASCADE',
|
||||
})
|
||||
type: ConceptType;
|
||||
|
||||
@@ -2,6 +2,7 @@ import {
|
||||
Column,
|
||||
Entity,
|
||||
OneToMany,
|
||||
PrimaryColumn,
|
||||
PrimaryGeneratedColumn,
|
||||
Unique,
|
||||
} from 'typeorm';
|
||||
@@ -10,7 +11,7 @@ import { Concept } from './concept.entity';
|
||||
@Entity()
|
||||
@Unique(['value'])
|
||||
export class ConceptType {
|
||||
@PrimaryGeneratedColumn()
|
||||
@PrimaryColumn()
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
|
||||
+2
-1
@@ -12,6 +12,7 @@
|
||||
"baseUrl": "./",
|
||||
"incremental": true,
|
||||
"skipLibCheck": true,
|
||||
"esModuleInterop": true
|
||||
"esModuleInterop": true,
|
||||
"resolveJsonModule": true
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user