Skip to content

Commit

Permalink
[release 0.0.4] Merges develop on staging (#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
rhuam committed May 30, 2024
2 parents f039469 + 55a1a9a commit 1043df2
Show file tree
Hide file tree
Showing 20 changed files with 432 additions and 31 deletions.
1 change: 1 addition & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:

jobs:
build:
if: github.repository == 'SOS-RS/backend'
runs-on: self-hosted

steps:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:

jobs:
build:
if: github.repository == 'SOS-RS/backend'
runs-on: dev

steps:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:

jobs:
build:
if: github.repository == 'SOS-RS/backend'
runs-on: stg

steps:
Expand Down
35 changes: 35 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"@nestjs/jwt": "^10.2.0",
"@nestjs/passport": "^10.0.3",
"@nestjs/platform-fastify": "^10.3.8",
"@nestjs/schedule": "^4.0.2",
"@nestjs/swagger": "^7.3.1",
"@prisma/client": "^5.13.0",
"bcrypt": "^5.1.1",
Expand Down
2 changes: 1 addition & 1 deletion prisma/dev_dump.sql
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ INSERT INTO public.users VALUES ('e0306bc0-8c29-429a-bbd2-384f48d4f993', 'Dinho'
INSERT INTO public.users VALUES ('e82f476a-1574-4dd2-a4c4-1c1f0117db12', 'Rhuam', '51992047974', '$2b$10$V4hFTbT7MrskROc4TI2lNe6gAd0g7U1niziAPycFueLhPJRFIfoGm', '51992047974', '2024-05-05T22:06:11.390Z', '2024-05-16T18:52:36.650Z', 'Admin', 'Estevam');


--
---
-- Data for Name: shelters; Type: TABLE DATA; Schema: public; Owner: doadmin
--

Expand Down
2 changes: 2 additions & 0 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { SupplyCategoriesModule } from './supply-categories/supply-categories.mo
import { ShelterManagersModule } from './shelter-managers/shelter-managers.module';
import { ShelterSupplyModule } from './shelter-supply/shelter-supply.module';
import { PartnersModule } from './partners/partners.module';
import { DashboardModule } from './modules/dashboard/dashboard.module';
import { SupportersModule } from './supporters/supporters.module';
import { SuppliesHistoryModule } from './supplies-history/supplies-history.module';

Expand All @@ -26,6 +27,7 @@ import { SuppliesHistoryModule } from './supplies-history/supplies-history.modul
ShelterManagersModule,
ShelterSupplyModule,
PartnersModule,
DashboardModule,
SupportersModule,
SuppliesHistoryModule,
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import { Observable } from 'rxjs';

import { ShelterSupplyHistoryAction } from './types';
import { handler } from './utils';
import { prisma } from '../../../prisma/prisma.service';
import { PrismaService } from '../../../prisma/prisma.service';

@Injectable()
export class ShelterSupplyHistoryInterceptor implements NestInterceptor {
constructor(private readonly action: ShelterSupplyHistoryAction) {}

intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
const request = context.switchToHttp().getRequest();
handler(prisma, this.action, request);
handler(PrismaService.getInstance(), this.action, request);
return next.handle();
}
}
20 changes: 6 additions & 14 deletions src/interceptors/interceptors/shelter-supply-history/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@ import { ShelterSupplyHistoryAction, UserIdentity } from './types';
import { getSessionData } from '@/utils/utils';

function registerSupplyLog(
prismaService: PrismaService,
body: z.infer<typeof CreateSupplyHistorySchema>,
user: UserIdentity,
user: UserIdentity = {},
) {
const fn = async () => {
const { shelterId, supplyId, ...rest } =
CreateSupplyHistorySchema.parse(body);

const prev = await prismaService.supplyHistory.findFirst({
const prev = await PrismaService.getInstance().supplyHistory.findFirst({
where: {
shelterId,
supplyId,
Expand All @@ -32,7 +31,7 @@ function registerSupplyLog(
},
});

await prismaService.supplyHistory.create({
await PrismaService.getInstance().supplyHistory.create({
data: {
shelterId,
supplyId,
Expand All @@ -57,23 +56,20 @@ function registerSupplyLog(
}

function registerCreateSupplyLog(
prismaService: PrismaService,
body: z.infer<typeof CreateShelterSupplySchema>,
user: UserIdentity,
) {
const payload = CreateShelterSupplySchema.parse(body);
registerSupplyLog(prismaService, payload, user);
registerSupplyLog(payload, user);
}

function registerUpdateSupplyLog(
prismaService: PrismaService,
body: z.infer<typeof UpdateShelterSupplySchema>,
user: UserIdentity,
) {
const payload = UpdateShelterSupplySchema.parse(body);

registerSupplyLog(
prismaService,
{
shelterId: payload.where.shelterId,
supplyId: payload.where.supplyId,
Expand All @@ -85,15 +81,13 @@ function registerUpdateSupplyLog(
}

function registerUpdateManySupplyLog(
prismaService: PrismaService,
body: z.infer<typeof UpdateManyShelterSupplySchema>,
user: UserIdentity,
) {
const { ids, shelterId } = UpdateManyShelterSupplySchema.parse(body);

ids.forEach((id) =>
registerSupplyLog(
prismaService,
{
shelterId,
supplyId: id,
Expand Down Expand Up @@ -124,11 +118,10 @@ function handler(

switch (action) {
case ShelterSupplyHistoryAction.Create:
registerCreateSupplyLog(prismaService, request.body as any, user);
registerCreateSupplyLog(request.body as any, user);
break;
case ShelterSupplyHistoryAction.Update:
registerUpdateSupplyLog(
prismaService,
{
data: request.body as any,
where: request.params as any,
Expand All @@ -138,7 +131,6 @@ function handler(
break;
case ShelterSupplyHistoryAction.UpdateMany:
registerUpdateManySupplyLog(
prismaService,
{
shelterId: (request.params as any).shelterId,
ids: (request.body as any).ids,
Expand All @@ -149,4 +141,4 @@ function handler(
}
}

export { handler };
export { handler, registerSupplyLog };
20 changes: 20 additions & 0 deletions src/modules/dashboard/dashboard.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Test, TestingModule } from '@nestjs/testing';
import { DashboardController } from './dashboard.controller';
import { DashboardService } from './dashboard.service';

describe('DashboardController', () => {
let controller: DashboardController;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [DashboardController],
providers: [DashboardService],
}).compile();

controller = module.get<DashboardController>(DashboardController);
});

it('should be defined', () => {
expect(controller).toBeDefined();
});
});
22 changes: 22 additions & 0 deletions src/modules/dashboard/dashboard.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Controller, Get, HttpException, Logger, Query } from '@nestjs/common';
import { DashboardService } from './dashboard.service';
import { ServerResponse } from '@/utils/utils';
import { ApiTags } from '@nestjs/swagger';

@ApiTags('Dashboard')
@Controller('dashboard')
export class DashboardController {
private logger = new Logger();
constructor(private readonly dashboardService: DashboardService) {}

@Get('')
async index(@Query() query) {
try {
const data = await this.dashboardService.index(query);
return new ServerResponse(200, 'Successfully get dashboard', data);
} catch (err: any) {
this.logger.error(`Failed to get shelters: ${err}`);
throw new HttpException(err?.code ?? err?.name ?? `${err}`, 400);
}
}
}
11 changes: 11 additions & 0 deletions src/modules/dashboard/dashboard.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Module } from '@nestjs/common';
import { DashboardService } from './dashboard.service';
import { DashboardController } from './dashboard.controller';
import { PrismaModule } from 'src/prisma/prisma.module';

@Module({
imports: [PrismaModule],
controllers: [DashboardController],
providers: [DashboardService],
})
export class DashboardModule {}
18 changes: 18 additions & 0 deletions src/modules/dashboard/dashboard.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { DashboardService } from './dashboard.service';

describe('DashboardService', () => {
let service: DashboardService;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [DashboardService],
}).compile();

service = module.get<DashboardService>(DashboardService);
});

it('should be defined', () => {
expect(service).toBeDefined();
});
});
Loading

0 comments on commit 1043df2

Please sign in to comment.