Skip to content

Instantly share code, notes, and snippets.

View nmchenry01's full-sized avatar

Nicholas McHenry nmchenry01

  • Boulder, CO
View GitHub Profile
@nmchenry01
nmchenry01 / task.dto.ts
Created August 25, 2020 14:39
ApiProperty decorator "NestJS with Swagger"
export class Task {
@ApiProperty()
id: string;
@ApiProperty()
title: string;
@ApiProperty()
description: string;
@nmchenry01
nmchenry01 / getTaskById.ts
Created August 25, 2020 13:52
API operations decorators "NestJS with Swagger"
@ApiOkResponse({
description: 'Retrieved task by ID successfully',
type: Task
})
@ApiNotFoundResponse({ description: 'No task found for ID' })
@ApiInternalServerErrorResponse({
description: 'Internal server error',
})
@Get(':id')
getTask(@Param('id') taskId: string): Task {
@nmchenry01
nmchenry01 / task.controller.ts
Created August 24, 2020 18:22
ApiTags decorator"NestJS with Swagger"
@ApiTags('task')
@Controller('task')
export class TaskController {}
@nmchenry01
nmchenry01 / main.ts
Created August 24, 2020 12:09
Bootstrap with swagger "NestJS with Swagger"
async function bootstrap() {
const app = await NestFactory.create(AppModule);
const APP_NAME = process.env.npm_package_name;
const APP_VERSION = process.env.npm_package_version;
const options = new DocumentBuilder()
.setTitle(APP_NAME)
.setDescription(`The ${APP_NAME} API description`)
.setVersion(APP_VERSION)
@nmchenry01
nmchenry01 / task.dto.ts
Created August 24, 2020 11:27
Task DTO "NestJS with Swagger"
export class Task {
id: string;
title: string;
description: string;
dateTimeCreated: string;
}
@nmchenry01
nmchenry01 / createTask.dto.ts
Created August 24, 2020 11:26
Create task DTO "NestJS with Swagger"
export class CreateTask {
@IsNotEmpty()
@IsString()
title: string;
@IsNotEmpty()
@IsString()
description: string;
}
@nmchenry01
nmchenry01 / task.service.ts
Created August 24, 2020 11:25
Task service "NestJS with Swagger"
@Injectable()
export class TaskService {
private tasks: Task[] = [];
createTask(createTask: CreateTask): Task {
const { title, description } = createTask;
const newTask: Task = {
id: uuidv4(),
title,
@nmchenry01
nmchenry01 / task.controller.ts
Created August 24, 2020 11:25
Beginning task controller "NestJS with Swagger"
@Controller('task')
export class TaskController {
constructor(private readonly taskService: TaskService) { }
@Get()
getTasks(): Task[] {
return this.taskService.getTasks();
}
@Get(':id')
@nmchenry01
nmchenry01 / rawSQL.ts
Created August 23, 2020 21:49
Raw SQL TypeORM for "Prisma vs. TypeORM"
const rawSQLQuery = async () => {
const companyRepository = getRepository(Company);
return companyRepository.query('SELECT * FROM "company"');
};
@nmchenry01
nmchenry01 / rawSQL.ts
Created August 23, 2020 21:48
Raw SQL Prisma for "Prisma vs. TypeORM"
const rawSQLQuery = (prisma: PrismaClient) => {
return prisma.queryRaw('SELECT * FROM "Company";');
};