-
Notifications
You must be signed in to change notification settings - Fork 296
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
Showing
14 changed files
with
273 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,34 @@ | ||
name: Deploy Backend in Development Enviroment | ||
|
||
on: | ||
push: | ||
branches: [develop] | ||
|
||
jobs: | ||
build: | ||
runs-on: dev | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Create .env file | ||
run: | | ||
touch .env | ||
echo TZ=${{ secrets.TZ }} >> .env | ||
echo DB_HOST=${{ secrets.DB_HOST }} >> .env | ||
echo DB_PORT=${{ secrets.DB_PORT }} >> .env | ||
echo DB_USER=${{ secrets.DB_USER }} >> .env | ||
echo DB_PASSWORD=${{ secrets.DB_PASSWORD }} >> .env | ||
echo DB_DATABASE_NAME=${{ secrets.DEV_DB_DATABASE_NAME }} >> .env | ||
echo DATABASE_URL=postgresql://${{ secrets.DB_USER }}:${{ secrets.DB_PASSWORD }}@${{ secrets.DB_HOST }}:${{ secrets.DB_PORT }}/${{ secrets.DEV_DB_DATABASE_NAME }}?schema=public >> .env | ||
echo SECRET_KEY=${{ secrets.SECRET_KEY }} >> .env | ||
echo HOST=${{ secrets.HOST }} >> .env | ||
echo PORT=${{ secrets.PORT }} >> .env | ||
echo SERVER_USER_PASSWORD=${{ secrets.SERVER_USER_PASSWORD }} >> .env | ||
cat .env | ||
- name: Remove old docker image | ||
run: echo ${{ secrets.SERVER_USER_PASSWORD }} | sudo -S docker compose down --rmi all | ||
|
||
- name: Create new docker image | ||
run: echo ${{ secrets.SERVER_USER_PASSWORD }} | sudo -S docker compose up -d --force-recreate |
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,34 @@ | ||
name: Deploy Backend in Development Enviroment | ||
|
||
on: | ||
push: | ||
branches: [staging] | ||
|
||
jobs: | ||
build: | ||
runs-on: stg | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Create .env file | ||
run: | | ||
touch .env | ||
echo TZ=${{ secrets.TZ }} >> .env | ||
echo DB_HOST=${{ secrets.DB_HOST }} >> .env | ||
echo DB_PORT=${{ secrets.DB_PORT }} >> .env | ||
echo DB_USER=${{ secrets.DB_USER }} >> .env | ||
echo DB_PASSWORD=${{ secrets.DB_PASSWORD }} >> .env | ||
echo DB_DATABASE_NAME=${{ secrets.STG_DB_DATABASE_NAME }} >> .env | ||
echo DATABASE_URL=postgresql://${{ secrets.DB_USER }}:${{ secrets.DB_PASSWORD }}@${{ secrets.DB_HOST }}:${{ secrets.DB_PORT }}/${{ secrets.STG_DB_DATABASE_NAME }}?schema=public >> .env | ||
echo SECRET_KEY=${{ secrets.SECRET_KEY }} >> .env | ||
echo HOST=${{ secrets.HOST }} >> .env | ||
echo PORT=${{ secrets.PORT }} >> .env | ||
echo SERVER_USER_PASSWORD=${{ secrets.SERVER_USER_PASSWORD }} >> .env | ||
cat .env | ||
- name: Remove old docker image | ||
run: echo ${{ secrets.SERVER_USER_PASSWORD }} | sudo -S docker compose down --rmi all | ||
|
||
- name: Create new docker image | ||
run: echo ${{ secrets.SERVER_USER_PASSWORD }} | sudo -S docker compose up -d --force-recreate |
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 "supporters" ( | ||
"id" TEXT NOT NULL, | ||
"name" TEXT NOT NULL, | ||
"image_url" TEXT NOT NULL, | ||
"link" TEXT NOT NULL, | ||
"created_at" VARCHAR(32) NOT NULL, | ||
"updated_at" VARCHAR(32), | ||
|
||
CONSTRAINT "supporters_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "supporters_name_key" ON "supporters"("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
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,17 @@ | ||
import z from 'zod'; | ||
|
||
const PartnerSchema = z.object({ | ||
id: z.string(), | ||
name: z.string(), | ||
link: z.string(), | ||
createdAt: z.string(), | ||
updatedAt: z.string().nullable().optional(), | ||
}); | ||
|
||
const CreatePartnerSchema = PartnerSchema.omit({ | ||
id: true, | ||
createdAt: true, | ||
updatedAt: true, | ||
}); | ||
|
||
export { PartnerSchema, CreatePartnerSchema }; |
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 { SupportersController } from './supporters.controller'; | ||
|
||
describe('SupportersController', () => { | ||
let controller: SupportersController; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
controllers: [SupportersController], | ||
}).compile(); | ||
|
||
controller = module.get<SupportersController>(SupportersController); | ||
}); | ||
|
||
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,43 @@ | ||
import { | ||
Body, | ||
Controller, | ||
Get, | ||
HttpException, | ||
Logger, | ||
Post, | ||
UseGuards, | ||
} from '@nestjs/common'; | ||
|
||
import { SupportersService } from './supporters.service'; | ||
import { ServerResponse } from '../utils'; | ||
import { AdminGuard } from '@/guards/admin.guard'; | ||
|
||
@Controller('supporters') | ||
export class SupportersController { | ||
private logger = new Logger(SupportersController.name); | ||
|
||
constructor(private readonly supportersService: SupportersService) {} | ||
|
||
@Get('') | ||
async index() { | ||
try { | ||
const data = await this.supportersService.index(); | ||
return new ServerResponse(200, 'Successfully get supporters', data); | ||
} catch (err: any) { | ||
this.logger.error(`Failed to get supporters: ${err}`); | ||
throw new HttpException(err?.code ?? err?.name ?? `${err}`, 400); | ||
} | ||
} | ||
|
||
@Post('') | ||
@UseGuards(AdminGuard) | ||
async store(@Body() body) { | ||
try { | ||
await this.supportersService.store(body); | ||
return new ServerResponse(200, 'Successfully created supporter'); | ||
} catch (err: any) { | ||
this.logger.error(`Failed to create supporter: ${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 { SupportersService } from './supporters.service'; | ||
import { SupportersController } from './supporters.controller'; | ||
import { PrismaModule } from '../prisma/prisma.module'; | ||
|
||
@Module({ | ||
imports: [PrismaModule], | ||
providers: [SupportersService], | ||
controllers: [SupportersController], | ||
}) | ||
export class SupportersModule {} |
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 { SupportersService } from './supporters.service'; | ||
|
||
describe('SupportersService', () => { | ||
let service: SupportersService; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [SupportersService], | ||
}).compile(); | ||
|
||
service = module.get<SupportersService>(SupportersService); | ||
}); | ||
|
||
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,21 @@ | ||
import { z } from 'zod'; | ||
import { Injectable } from '@nestjs/common'; | ||
|
||
import { PrismaService } from '../prisma/prisma.service'; | ||
import { CreateSupporterSchema } from './types'; | ||
|
||
@Injectable() | ||
export class SupportersService { | ||
constructor(private readonly prismaService: PrismaService) {} | ||
|
||
async index() { | ||
return await this.prismaService.supporters.findMany({}); | ||
} | ||
|
||
async store(body: z.infer<typeof CreateSupporterSchema>) { | ||
const payload = CreateSupporterSchema.parse(body); | ||
await this.prismaService.supporters.create({ | ||
data: { ...payload, createdAt: new Date().toISOString() }, | ||
}); | ||
} | ||
} |
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 z from 'zod'; | ||
|
||
const SupporterSchema = z.object({ | ||
id: z.string(), | ||
name: z.string(), | ||
imageUrl: z.string(), | ||
link: z.string(), | ||
createdAt: z.string(), | ||
updatedAt: z.string().nullable().optional(), | ||
}); | ||
|
||
const CreateSupporterSchema = SupporterSchema.omit({ | ||
id: true, | ||
createdAt: true, | ||
updatedAt: true, | ||
}); | ||
|
||
export { SupporterSchema, CreateSupporterSchema }; |