-
Notifications
You must be signed in to change notification settings - Fork 295
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
43384ca
commit ab4df98
Showing
9 changed files
with
111 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
-- CreateTable | ||
CREATE TABLE "partners" ( | ||
"id" TEXT NOT NULL, | ||
"name" TEXT NOT NULL, | ||
"link" TEXT NOT NULL, | ||
"iconName" TEXT NOT NULL DEFAULT 'Handshake', | ||
"created_at" VARCHAR(32) NOT NULL, | ||
"updated_at" VARCHAR(32), | ||
|
||
CONSTRAINT "partners_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "partners_name_key" ON "partners"("name"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { PartnersController } from './partners.controller'; | ||
|
||
describe('PartnersController', () => { | ||
let controller: PartnersController; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
controllers: [PartnersController], | ||
}).compile(); | ||
|
||
controller = module.get<PartnersController>(PartnersController); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(controller).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Controller, Get, HttpException, Logger } from '@nestjs/common'; | ||
import { PartnersService } from './partners.service'; | ||
import { ServerResponse } from '../utils'; | ||
|
||
@Controller('partners') | ||
export class PartnersController { | ||
private logger = new Logger(PartnersController.name); | ||
|
||
constructor(private readonly partnersService: PartnersService) {} | ||
|
||
@Get('') | ||
async index() { | ||
try { | ||
const data = await this.partnersService.index(); | ||
return new ServerResponse(200, 'Successfully get partners', data); | ||
} catch (err: any) { | ||
this.logger.error(`Failed to get partners: ${err}`); | ||
throw new HttpException(err?.code ?? err?.name ?? `${err}`, 400); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Module } from '@nestjs/common'; | ||
|
||
import { PartnersService } from './partners.service'; | ||
import { PartnersController } from './partners.controller'; | ||
import { PrismaModule } from '../prisma/prisma.module'; | ||
|
||
@Module({ | ||
imports: [PrismaModule], | ||
providers: [PartnersService], | ||
controllers: [PartnersController], | ||
}) | ||
export class PartnersModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { PartnersService } from './partners.service'; | ||
|
||
describe('PartnersService', () => { | ||
let service: PartnersService; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [PartnersService], | ||
}).compile(); | ||
|
||
service = module.get<PartnersService>(PartnersService); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(service).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { ApiTags } from '@nestjs/swagger'; | ||
|
||
import { PrismaService } from '../prisma/prisma.service'; | ||
|
||
@ApiTags('Parceiros') | ||
@Injectable() | ||
export class PartnersService { | ||
constructor(private readonly prismaService: PrismaService) {} | ||
|
||
async index() { | ||
return await this.prismaService.partners.findMany({}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters