format + lint
This commit is contained in:
@@ -1,34 +1,41 @@
|
||||
import { Column, CreateDateColumn, Entity, Index, PrimaryGeneratedColumn, UpdateDateColumn } from "typeorm";
|
||||
import {
|
||||
Column,
|
||||
CreateDateColumn,
|
||||
Entity,
|
||||
Index,
|
||||
PrimaryGeneratedColumn,
|
||||
UpdateDateColumn,
|
||||
} from 'typeorm';
|
||||
|
||||
type ResourceTag = {
|
||||
name: string;
|
||||
type: string;
|
||||
}
|
||||
name: string;
|
||||
type: string;
|
||||
};
|
||||
|
||||
@Entity()
|
||||
export class Resource {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
@Index()
|
||||
id: string;
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
@Index()
|
||||
id: string;
|
||||
|
||||
@Column()
|
||||
title: string;
|
||||
@Column()
|
||||
title: string;
|
||||
|
||||
@Column()
|
||||
description: string;
|
||||
@Column()
|
||||
description: string;
|
||||
|
||||
@Column()
|
||||
imageUrl: string;
|
||||
@Column()
|
||||
imageUrl: string;
|
||||
|
||||
@Column()
|
||||
link: string;
|
||||
@Column()
|
||||
link: string;
|
||||
|
||||
@Column('jsonb')
|
||||
tags: ResourceTag[];
|
||||
@Column('jsonb')
|
||||
tags: ResourceTag[];
|
||||
|
||||
@CreateDateColumn({ precision: 3 })
|
||||
createdAt: Date;
|
||||
@CreateDateColumn({ precision: 3 })
|
||||
createdAt: Date;
|
||||
|
||||
@UpdateDateColumn({ precision: 3 })
|
||||
updatedAt: Date;
|
||||
}
|
||||
@UpdateDateColumn({ precision: 3 })
|
||||
updatedAt: Date;
|
||||
}
|
||||
|
||||
@@ -3,13 +3,10 @@ import { ResourceService } from './resource.service';
|
||||
|
||||
@Controller('resource')
|
||||
export class ResourceController {
|
||||
constructor(private readonly resourceService: ResourceService) {}
|
||||
|
||||
constructor(
|
||||
private readonly resourceService: ResourceService,
|
||||
) { }
|
||||
|
||||
@Get()
|
||||
async getResource() {
|
||||
return this.resourceService.findAll();
|
||||
}
|
||||
@Get()
|
||||
async getResource() {
|
||||
return this.resourceService.findAll();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { Resource } from './entity/resource.entity';
|
||||
|
||||
@Module({
|
||||
imports:[TypeOrmModule.forFeature([Resource])],
|
||||
imports: [TypeOrmModule.forFeature([Resource])],
|
||||
controllers: [ResourceController],
|
||||
providers: [ResourceService],
|
||||
exports: [ResourceService],
|
||||
|
||||
@@ -5,34 +5,34 @@ import { InjectRepository } from '@nestjs/typeorm';
|
||||
|
||||
@Injectable()
|
||||
export class ResourceService {
|
||||
constructor(
|
||||
@InjectRepository(Resource)
|
||||
private readonly resourceRepository: Repository<Resource>,
|
||||
) { }
|
||||
constructor(
|
||||
@InjectRepository(Resource)
|
||||
private readonly resourceRepository: Repository<Resource>,
|
||||
) {}
|
||||
|
||||
async findAll(): Promise<Resource[]> {
|
||||
return this.resourceRepository.find({
|
||||
order: {
|
||||
createdAt: 'DESC',
|
||||
}
|
||||
});
|
||||
}
|
||||
async findAll(): Promise<Resource[]> {
|
||||
return this.resourceRepository.find({
|
||||
order: {
|
||||
createdAt: 'DESC',
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async findById(id: string): Promise<Resource> {
|
||||
return this.resourceRepository.findOne({ where: { id } });
|
||||
}
|
||||
async findById(id: string): Promise<Resource> {
|
||||
return this.resourceRepository.findOne({ where: { id } });
|
||||
}
|
||||
|
||||
async create(data: Partial<Resource>): Promise<Resource> {
|
||||
const resource = this.resourceRepository.create(data);
|
||||
return this.resourceRepository.save(resource);
|
||||
}
|
||||
async create(data: Partial<Resource>): Promise<Resource> {
|
||||
const resource = this.resourceRepository.create(data);
|
||||
return this.resourceRepository.save(resource);
|
||||
}
|
||||
|
||||
async update(id: string, data: Partial<Resource>): Promise<Resource> {
|
||||
await this.resourceRepository.update(id, data);
|
||||
return this.resourceRepository.findOne({ where: { id } });
|
||||
}
|
||||
async update(id: string, data: Partial<Resource>): Promise<Resource> {
|
||||
await this.resourceRepository.update(id, data);
|
||||
return this.resourceRepository.findOne({ where: { id } });
|
||||
}
|
||||
|
||||
async delete(id: string): Promise<void> {
|
||||
await this.resourceRepository.delete(id);
|
||||
}
|
||||
async delete(id: string): Promise<void> {
|
||||
await this.resourceRepository.delete(id);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user