-
Notifications
You must be signed in to change notification settings - Fork 284
Adicionados módulos de transportes e viagens #129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
vitor-msp
wants to merge
36
commits into
SOS-RS:develop
Choose a base branch
from
vitor-msp:feat/transports
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
f44dde7
feat: added prisma schema and migrations
vitor-msp d079fcf
feat: added transports module structure
vitor-msp 82a7acc
feat: added endpoint post transport
vitor-msp 4046efa
feat: added endpoint put transport
vitor-msp 07ecfcd
feat: added transport managers module structure
vitor-msp 6814988
feat: added endpoint post transport managers
vitor-msp c87943c
feat: added trips module structure
vitor-msp 461a79c
fix: changed name format of the some trip fields
vitor-msp 52fba27
feat: added endpoint post trip
vitor-msp cbe39e9
feat: added endpoint put trip
vitor-msp 2c3aa1a
feat: added field canceled in trips table
vitor-msp 2a275cd
feat: added endpoint delete trip
vitor-msp a597811
feat: added guards
vitor-msp 64bd391
feat: added user validation in the trips module
vitor-msp c023337
refactor: improved error messages
vitor-msp 325f732
feat: added endpoint get transports
vitor-msp e9641e0
feat: added endpoint get transport by id
vitor-msp d2a40e8
feat: added endpoint get trip by id
vitor-msp 9985a85
feat: added endpoint get trips
vitor-msp 96140c9
feat: changed departure_datetime field in trip to datetime
vitor-msp b8f774b
feat: trip search changed to use departure datetime range
vitor-msp 9118664
feat: added field departure_neighborhood in trips table
vitor-msp b485816
feat: added endpoint get trip cities
vitor-msp 0c24403
feat: added field departure_state in trips table
vitor-msp 4d49f92
feat: added endpoint get trip states
vitor-msp 1514c82
feat: added departure_state in the get trips filter
vitor-msp 0fb9add
Merge pull request #1 from SOS-RS/develop
vitor-msp 102cc76
Merge branch 'develop' into feat/transports
vitor-msp 8e5d4a8
fix: changed type of datetime fields
vitor-msp c05baea
fix: temporarily set departure_datetime to string
vitor-msp 8e7c09e
fix: changed type of departure_datetime field
vitor-msp 9133c56
Merge pull request #2 from SOS-RS/develop
vitor-msp 276e5c6
Merge branch 'develop' into feat/transports
vitor-msp 7f52a13
refactor: improved exceptions
vitor-msp bbe0332
Merge branch 'develop' into feat/transports
vitor-msp c91ec13
Merge branch 'develop' into feat/transports
vitor-msp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,47 @@ | ||
-- CreateTable | ||
CREATE TABLE "transports" ( | ||
"id" TEXT NOT NULL, | ||
"vehicle_type" TEXT NOT NULL, | ||
"vehicle_registration_plate" TEXT, | ||
"contact" TEXT, | ||
"created_at" VARCHAR(32) NOT NULL, | ||
"updated_at" VARCHAR(32), | ||
|
||
CONSTRAINT "transports_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "transport_managers" ( | ||
"transport_id" TEXT NOT NULL, | ||
"user_id" TEXT NOT NULL, | ||
"created_at" VARCHAR(32) NOT NULL, | ||
"updated_at" VARCHAR(32), | ||
|
||
CONSTRAINT "transport_managers_pkey" PRIMARY KEY ("transport_id","user_id") | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "trips" ( | ||
"id" TEXT NOT NULL, | ||
"transport_id" TEXT NOT NULL, | ||
"shelter_id" TEXT NOT NULL, | ||
"departure_city" TEXT NOT NULL, | ||
"departure_datetime" TIMESTAMP(3) NOT NULL, | ||
"contact" TEXT NOT NULL, | ||
"created_at" VARCHAR(32) NOT NULL, | ||
"updated_at" VARCHAR(32), | ||
|
||
CONSTRAINT "trips_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "transport_managers" ADD CONSTRAINT "transport_managers_transport_id_fkey" FOREIGN KEY ("transport_id") REFERENCES "transports"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "transport_managers" ADD CONSTRAINT "transport_managers_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "trips" ADD CONSTRAINT "trips_transport_id_fkey" FOREIGN KEY ("transport_id") REFERENCES "transports"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "trips" ADD CONSTRAINT "trips_shelter_id_fkey" FOREIGN KEY ("shelter_id") REFERENCES "shelters"("id") ON DELETE RESTRICT ON UPDATE CASCADE; |
This file contains hidden or 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,2 @@ | ||
-- AlterTable | ||
ALTER TABLE "trips" ALTER COLUMN "departure_datetime" SET DATA TYPE TEXT; |
This file contains hidden or 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,2 @@ | ||
-- AlterTable | ||
ALTER TABLE "trips" ADD COLUMN "canceled" BOOLEAN NOT NULL DEFAULT false; |
This file contains hidden or 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,2 @@ | ||
-- AlterEnum | ||
ALTER TYPE "AccessLevel" ADD VALUE 'TransportManager'; |
This file contains hidden or 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,9 @@ | ||
/* | ||
Warnings: | ||
|
||
- Changed the type of `departure_datetime` on the `trips` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required. | ||
|
||
*/ | ||
-- AlterTable | ||
ALTER TABLE "trips" DROP COLUMN "departure_datetime", | ||
ADD COLUMN "departure_datetime" TIMESTAMP(3) NOT NULL; |
This file contains hidden or 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,2 @@ | ||
-- AlterTable | ||
ALTER TABLE "trips" ADD COLUMN "departure_neighborhood" TEXT; |
This file contains hidden or 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,11 @@ | ||
/* | ||
Warnings: | ||
|
||
- Added the required column `departure_state` to the `trips` table without a default value. This is not possible if the table is not empty. | ||
|
||
*/ | ||
-- CreateEnum | ||
CREATE TYPE "State" AS ENUM ('AC', 'AL', 'AP', 'AM', 'BA', 'CE', 'DF', 'ES', 'GO', 'MA', 'MT', 'MS', 'MG', 'PA', 'PB', 'PR', 'PE', 'PI', 'RJ', 'RN', 'RS', 'RO', 'RR', 'SC', 'SP', 'SE', 'TO'); | ||
|
||
-- AlterTable | ||
ALTER TABLE "trips" ADD COLUMN "departure_state" "State" NOT NULL; |
This file contains hidden or 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,11 @@ | ||
-- ALTER TABLE | ||
ALTER TABLE "transport_managers" ALTER COLUMN "created_at" TYPE TIMESTAMP(3) WITH TIME ZONE USING TO_TIMESTAMP("created_at", 'YYYY-MM-DD"T"HH24:MI:SS.FF3"Z"')::TIMESTAMP; | ||
ALTER TABLE "transport_managers" ALTER COLUMN "updated_at" TYPE TIMESTAMP(3) WITH TIME ZONE USING TO_TIMESTAMP("updated_at", 'YYYY-MM-DD"T"HH24:MI:SS.FF3"Z"')::TIMESTAMP; | ||
|
||
-- ALTER TABLE | ||
ALTER TABLE "transports" ALTER COLUMN "created_at" TYPE TIMESTAMP(3) WITH TIME ZONE USING TO_TIMESTAMP("created_at", 'YYYY-MM-DD"T"HH24:MI:SS.FF3"Z"')::TIMESTAMP; | ||
ALTER TABLE "transports" ALTER COLUMN "updated_at" TYPE TIMESTAMP(3) WITH TIME ZONE USING TO_TIMESTAMP("updated_at", 'YYYY-MM-DD"T"HH24:MI:SS.FF3"Z"')::TIMESTAMP; | ||
|
||
-- ALTER TABLE | ||
ALTER TABLE "trips" ALTER COLUMN "created_at" TYPE TIMESTAMP(3) WITH TIME ZONE USING TO_TIMESTAMP("created_at", 'YYYY-MM-DD"T"HH24:MI:SS.FF3"Z"')::TIMESTAMP; | ||
ALTER TABLE "trips" ALTER COLUMN "updated_at" TYPE TIMESTAMP(3) WITH TIME ZONE USING TO_TIMESTAMP("updated_at", 'YYYY-MM-DD"T"HH24:MI:SS.FF3"Z"')::TIMESTAMP; |
This file contains hidden or 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,9 @@ | ||
-- AlterTable | ||
ALTER TABLE "transport_managers" ALTER COLUMN "created_at" SET DEFAULT CURRENT_TIMESTAMP; | ||
|
||
-- AlterTable | ||
ALTER TABLE "transports" ALTER COLUMN "created_at" SET DEFAULT CURRENT_TIMESTAMP; | ||
|
||
-- AlterTable | ||
ALTER TABLE "trips" ALTER COLUMN "created_at" SET DEFAULT CURRENT_TIMESTAMP, | ||
ALTER COLUMN "departure_datetime" SET DATA TYPE TEXT; |
This file contains hidden or 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,2 @@ | ||
-- ALTER TABLE | ||
ALTER TABLE "trips" ALTER COLUMN "departure_datetime" TYPE TIMESTAMP(3) WITH TIME ZONE USING TO_TIMESTAMP("departure_datetime", 'YYYY-MM-DD"T"HH24:MI:SS.FF3"Z"')::TIMESTAMP; |
This file contains hidden or 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 hidden or 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 hidden or 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,23 @@ | ||
import { ExecutionContext, HttpException, Injectable, UnauthorizedException } from '@nestjs/common'; | ||
import { AuthGuard } from '@nestjs/passport'; | ||
import { AccessLevel } from '@prisma/client'; | ||
|
||
import { canActivate } from './utils'; | ||
|
||
@Injectable() | ||
export class TransportManagerGuard extends AuthGuard('jwt') { | ||
constructor() { | ||
super(); | ||
} | ||
|
||
async canActivate(context: ExecutionContext): Promise<boolean> { | ||
await super.canActivate(context); | ||
const ok = await canActivate(context, [ | ||
AccessLevel.TransportManager, | ||
AccessLevel.Staff, | ||
AccessLevel.Admin, | ||
]); | ||
if (ok) return true; | ||
throw new UnauthorizedException('Acesso não autorizado'); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/transport-managers/transport-managers.controller.spec.ts
This file contains hidden or 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 { TransportManagersController } from './transport-managers.controller'; | ||
|
||
describe('TransportManagersController', () => { | ||
let controller: TransportManagersController; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
controllers: [TransportManagersController], | ||
}).compile(); | ||
|
||
controller = module.get<TransportManagersController>(TransportManagersController); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(controller).toBeDefined(); | ||
}); | ||
}); |
This file contains hidden or 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 @@ | ||
import { | ||
Body, | ||
Controller, | ||
HttpException, | ||
Logger, | ||
Post, | ||
UseGuards, | ||
} from '@nestjs/common'; | ||
import { TransportManagersService } from './transport-managers.service'; | ||
import { ApiTags } from '@nestjs/swagger'; | ||
import { ServerResponse } from '../utils'; | ||
import { StaffGuard } from '@/guards/staff.guard'; | ||
|
||
@ApiTags('Transport Managers') | ||
@Controller('transport/managers') | ||
export class TransportManagersController { | ||
private logger = new Logger(TransportManagersController.name); | ||
|
||
constructor( | ||
private readonly transportManagersService: TransportManagersService, | ||
) {} | ||
|
||
@Post('') | ||
@UseGuards(StaffGuard) | ||
async store(@Body() body) { | ||
try { | ||
await this.transportManagersService.store(body); | ||
return new ServerResponse(200, 'Successfully added manager to transport'); | ||
} catch (err: any) { | ||
this.logger.error(`Failed to added manager to transport: ${err}`); | ||
throw new HttpException(err?.code ?? err?.name ?? `${err}`, 400); | ||
} | ||
} | ||
} |
This file contains hidden or 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,11 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { TransportManagersService } from './transport-managers.service'; | ||
import { TransportManagersController } from './transport-managers.controller'; | ||
import { PrismaModule } from 'src/prisma/prisma.module'; | ||
|
||
@Module({ | ||
imports: [PrismaModule], | ||
providers: [TransportManagersService], | ||
controllers: [TransportManagersController], | ||
}) | ||
export class TransportManagersModule {} |
This file contains hidden or 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 { TransportManagersService } from './transport-managers.service'; | ||
|
||
describe('TransportManagersService', () => { | ||
let service: TransportManagersService; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [TransportManagersService], | ||
}).compile(); | ||
|
||
service = module.get<TransportManagersService>(TransportManagersService); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(service).toBeDefined(); | ||
}); | ||
}); |
This file contains hidden or 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,41 @@ | ||
import { Injectable, NotFoundException } from '@nestjs/common'; | ||
import { PrismaService } from 'src/prisma/prisma.service'; | ||
import { z } from 'zod'; | ||
import { CreateTransportManagerSchema } from './types'; | ||
|
||
@Injectable() | ||
export class TransportManagersService { | ||
constructor(private readonly prismaService: PrismaService) {} | ||
|
||
async store(body: z.infer<typeof CreateTransportManagerSchema>) { | ||
const { transportId, userId } = CreateTransportManagerSchema.parse(body); | ||
|
||
let result = await this.prismaService.transport.findFirst({ | ||
where: { | ||
id: transportId, | ||
}, | ||
select: { | ||
id: true, | ||
}, | ||
}); | ||
if (!result) throw new NotFoundException('Transporte não encontrado.'); | ||
|
||
result = await this.prismaService.user.findFirst({ | ||
where: { | ||
id: userId, | ||
}, | ||
select: { | ||
id: true, | ||
}, | ||
}); | ||
if (!result) throw new NotFoundException('Usuário não encontrado.'); | ||
|
||
await this.prismaService.transportManager.create({ | ||
data: { | ||
transportId, | ||
userId, | ||
createdAt: new Date().toISOString(), | ||
}, | ||
}); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.