feat: add theater service
This commit is contained in:
commit
81003652d7
58
.gitignore
vendored
Normal file
58
.gitignore
vendored
Normal file
@ -0,0 +1,58 @@
|
||||
# compiled output
|
||||
/dist
|
||||
/node_modules
|
||||
/build
|
||||
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
pnpm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
|
||||
# OS
|
||||
.DS_Store
|
||||
|
||||
# Tests
|
||||
/coverage
|
||||
/.nyc_output
|
||||
|
||||
# IDEs and editors
|
||||
/.idea
|
||||
.project
|
||||
.classpath
|
||||
.c9/
|
||||
*.launch
|
||||
.settings/
|
||||
*.sublime-workspace
|
||||
|
||||
# IDE - VSCode
|
||||
.vscode/*
|
||||
!.vscode/settings.json
|
||||
!.vscode/tasks.json
|
||||
!.vscode/launch.json
|
||||
!.vscode/extensions.json
|
||||
|
||||
# dotenv environment variable files
|
||||
.env
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
.env.local
|
||||
|
||||
# temp directory
|
||||
.temp
|
||||
.tmp
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||
|
||||
/prisma/generated
|
||||
98
README.md
Normal file
98
README.md
Normal file
@ -0,0 +1,98 @@
|
||||
<p align="center">
|
||||
<a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="120" alt="Nest Logo" /></a>
|
||||
</p>
|
||||
|
||||
[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456
|
||||
[circleci-url]: https://circleci.com/gh/nestjs/nest
|
||||
|
||||
<p align="center">A progressive <a href="http://nodejs.org" target="_blank">Node.js</a> framework for building efficient and scalable server-side applications.</p>
|
||||
<p align="center">
|
||||
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a>
|
||||
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a>
|
||||
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/dm/@nestjs/common.svg" alt="NPM Downloads" /></a>
|
||||
<a href="https://circleci.com/gh/nestjs/nest" target="_blank"><img src="https://img.shields.io/circleci/build/github/nestjs/nest/master" alt="CircleCI" /></a>
|
||||
<a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a>
|
||||
<a href="https://opencollective.com/nest#backer" target="_blank"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
|
||||
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
|
||||
<a href="https://paypal.me/kamilmysliwiec" target="_blank"><img src="https://img.shields.io/badge/Donate-PayPal-ff3f59.svg" alt="Donate us"/></a>
|
||||
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://img.shields.io/badge/Support%20us-Open%20Collective-41B883.svg" alt="Support us"></a>
|
||||
<a href="https://twitter.com/nestframework" target="_blank"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow" alt="Follow us on Twitter"></a>
|
||||
</p>
|
||||
<!--[](https://opencollective.com/nest#backer)
|
||||
[](https://opencollective.com/nest#sponsor)-->
|
||||
|
||||
## Description
|
||||
|
||||
[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository.
|
||||
|
||||
## Project setup
|
||||
|
||||
```bash
|
||||
$ yarn install
|
||||
```
|
||||
|
||||
## Compile and run the project
|
||||
|
||||
```bash
|
||||
# development
|
||||
$ yarn run start
|
||||
|
||||
# watch mode
|
||||
$ yarn run start:dev
|
||||
|
||||
# production mode
|
||||
$ yarn run start:prod
|
||||
```
|
||||
|
||||
## Run tests
|
||||
|
||||
```bash
|
||||
# unit tests
|
||||
$ yarn run test
|
||||
|
||||
# e2e tests
|
||||
$ yarn run test:e2e
|
||||
|
||||
# test coverage
|
||||
$ yarn run test:cov
|
||||
```
|
||||
|
||||
## Deployment
|
||||
|
||||
When you're ready to deploy your NestJS application to production, there are some key steps you can take to ensure it runs as efficiently as possible. Check out the [deployment documentation](https://docs.nestjs.com/deployment) for more information.
|
||||
|
||||
If you are looking for a cloud-based platform to deploy your NestJS application, check out [Mau](https://mau.nestjs.com), our official platform for deploying NestJS applications on AWS. Mau makes deployment straightforward and fast, requiring just a few simple steps:
|
||||
|
||||
```bash
|
||||
$ yarn install -g @nestjs/mau
|
||||
$ mau deploy
|
||||
```
|
||||
|
||||
With Mau, you can deploy your application in just a few clicks, allowing you to focus on building features rather than managing infrastructure.
|
||||
|
||||
## Resources
|
||||
|
||||
Check out a few resources that may come in handy when working with NestJS:
|
||||
|
||||
- Visit the [NestJS Documentation](https://docs.nestjs.com) to learn more about the framework.
|
||||
- For questions and support, please visit our [Discord channel](https://discord.gg/G7Qnnhy).
|
||||
- To dive deeper and get more hands-on experience, check out our official video [courses](https://courses.nestjs.com/).
|
||||
- Deploy your application to AWS with the help of [NestJS Mau](https://mau.nestjs.com) in just a few clicks.
|
||||
- Visualize your application graph and interact with the NestJS application in real-time using [NestJS Devtools](https://devtools.nestjs.com).
|
||||
- Need help with your project (part-time to full-time)? Check out our official [enterprise support](https://enterprise.nestjs.com).
|
||||
- To stay in the loop and get updates, follow us on [X](https://x.com/nestframework) and [LinkedIn](https://linkedin.com/company/nestjs).
|
||||
- Looking for a job, or have a job to offer? Check out our official [Jobs board](https://jobs.nestjs.com).
|
||||
|
||||
## Support
|
||||
|
||||
Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support).
|
||||
|
||||
## Stay in touch
|
||||
|
||||
- Author - [Kamil Myśliwiec](https://twitter.com/kammysliwiec)
|
||||
- Website - [https://nestjs.com](https://nestjs.com/)
|
||||
- Twitter - [@nestframework](https://twitter.com/nestframework)
|
||||
|
||||
## License
|
||||
|
||||
Nest is [MIT licensed](https://github.com/nestjs/nest/blob/master/LICENSE).
|
||||
35
eslint.config.mjs
Normal file
35
eslint.config.mjs
Normal file
@ -0,0 +1,35 @@
|
||||
// @ts-check
|
||||
import eslint from '@eslint/js';
|
||||
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
|
||||
import globals from 'globals';
|
||||
import tseslint from 'typescript-eslint';
|
||||
|
||||
export default tseslint.config(
|
||||
{
|
||||
ignores: ['eslint.config.mjs'],
|
||||
},
|
||||
eslint.configs.recommended,
|
||||
...tseslint.configs.recommendedTypeChecked,
|
||||
eslintPluginPrettierRecommended,
|
||||
{
|
||||
languageOptions: {
|
||||
globals: {
|
||||
...globals.node,
|
||||
...globals.jest,
|
||||
},
|
||||
sourceType: 'commonjs',
|
||||
parserOptions: {
|
||||
projectService: true,
|
||||
tsconfigRootDir: import.meta.dirname,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
rules: {
|
||||
'@typescript-eslint/no-explicit-any': 'off',
|
||||
'@typescript-eslint/no-floating-promises': 'warn',
|
||||
'@typescript-eslint/no-unsafe-argument': 'warn',
|
||||
"prettier/prettier": ["error", { endOfLine: "auto" }],
|
||||
},
|
||||
},
|
||||
);
|
||||
8
nest-cli.json
Normal file
8
nest-cli.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/nest-cli",
|
||||
"collection": "@nestjs/schematics",
|
||||
"sourceRoot": "src",
|
||||
"compilerOptions": {
|
||||
"deleteOutDir": true
|
||||
}
|
||||
}
|
||||
81
package.json
Normal file
81
package.json
Normal file
@ -0,0 +1,81 @@
|
||||
{
|
||||
"name": "theater-service",
|
||||
"version": "0.0.1",
|
||||
"description": "",
|
||||
"author": "",
|
||||
"private": true,
|
||||
"license": "UNLICENSED",
|
||||
"scripts": {
|
||||
"build": "nest build",
|
||||
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
|
||||
"start": "nest start",
|
||||
"start:dev": "nest start --watch",
|
||||
"start:debug": "nest start --debug --watch",
|
||||
"start:prod": "node dist/main",
|
||||
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
|
||||
"test": "jest",
|
||||
"test:watch": "jest --watch",
|
||||
"test:cov": "jest --coverage",
|
||||
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
|
||||
"test:e2e": "jest --config ./test/jest-e2e.json"
|
||||
},
|
||||
"dependencies": {
|
||||
"@grpc/grpc-js": "^1.14.3",
|
||||
"@grpc/proto-loader": "^0.8.0",
|
||||
"@nestjs/common": "^11.0.1",
|
||||
"@nestjs/config": "^4.0.4",
|
||||
"@nestjs/core": "^11.0.1",
|
||||
"@nestjs/microservices": "^11.1.19",
|
||||
"@nestjs/platform-express": "^11.0.1",
|
||||
"@prisma/adapter-pg": "^7.7.0",
|
||||
"@prisma/client": "^7.7.0",
|
||||
"@teacinema/common": "^1.4.0",
|
||||
"@teacinema/contracts": "^1.3.1",
|
||||
"prisma": "^7.7.0",
|
||||
"reflect-metadata": "^0.2.2",
|
||||
"rxjs": "^7.8.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/eslintrc": "^3.2.0",
|
||||
"@eslint/js": "^9.18.0",
|
||||
"@nestjs/cli": "^11.0.0",
|
||||
"@nestjs/schematics": "^11.0.0",
|
||||
"@nestjs/testing": "^11.0.1",
|
||||
"@teacinema/core": "^1.0.9",
|
||||
"@types/express": "^5.0.0",
|
||||
"@types/jest": "^30.0.0",
|
||||
"@types/node": "^22.10.7",
|
||||
"@types/supertest": "^6.0.2",
|
||||
"eslint": "^9.18.0",
|
||||
"eslint-config-prettier": "^10.0.1",
|
||||
"eslint-plugin-prettier": "^5.2.2",
|
||||
"globals": "^16.0.0",
|
||||
"jest": "^30.0.0",
|
||||
"prettier": "^3.4.2",
|
||||
"source-map-support": "^0.5.21",
|
||||
"supertest": "^7.0.0",
|
||||
"ts-jest": "^29.2.5",
|
||||
"ts-loader": "^9.5.2",
|
||||
"ts-node": "^10.9.2",
|
||||
"tsconfig-paths": "^4.2.0",
|
||||
"typescript": "^5.7.3",
|
||||
"typescript-eslint": "^8.20.0"
|
||||
},
|
||||
"jest": {
|
||||
"moduleFileExtensions": [
|
||||
"js",
|
||||
"json",
|
||||
"ts"
|
||||
],
|
||||
"rootDir": "src",
|
||||
"testRegex": ".*\\.spec\\.ts$",
|
||||
"transform": {
|
||||
"^.+\\.(t|j)s$": "ts-jest"
|
||||
},
|
||||
"collectCoverageFrom": [
|
||||
"**/*.(t|j)s"
|
||||
],
|
||||
"coverageDirectory": "../coverage",
|
||||
"testEnvironment": "node"
|
||||
}
|
||||
}
|
||||
7
prettier.config.mjs
Normal file
7
prettier.config.mjs
Normal file
@ -0,0 +1,7 @@
|
||||
import config from '@teacinema/core/prettier'
|
||||
|
||||
export default {
|
||||
...config,
|
||||
tabWidth: 2,
|
||||
useTabs: false,
|
||||
};
|
||||
16
prisma.config.ts
Normal file
16
prisma.config.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import dotenv from 'dotenv'
|
||||
import dotenvExpand from 'dotenv-expand'
|
||||
import { defineConfig } from 'prisma/config'
|
||||
|
||||
const env = dotenv.config({ path: '.env' })
|
||||
dotenvExpand.expand(env)
|
||||
|
||||
export default defineConfig({
|
||||
schema: 'prisma/schema.prisma',
|
||||
migrations: {
|
||||
path: 'prisma/migrations'
|
||||
},
|
||||
datasource: {
|
||||
url: process.env['DATABASE_URI']
|
||||
}
|
||||
})
|
||||
26
prisma/schema.prisma
Normal file
26
prisma/schema.prisma
Normal file
@ -0,0 +1,26 @@
|
||||
// This is your Prisma schema file,
|
||||
// learn more about it in the docs: https://pris.ly/d/prisma-schema
|
||||
|
||||
// Get a free hosted Postgres database in seconds: `npx create-db`
|
||||
|
||||
generator client {
|
||||
provider = "prisma-client"
|
||||
output = "./generated"
|
||||
moduleFormat = "cjs"
|
||||
}
|
||||
|
||||
datasource db {
|
||||
provider = "postgresql"
|
||||
}
|
||||
|
||||
model Theater {
|
||||
id String @id @default(nanoid())
|
||||
|
||||
name String
|
||||
address String
|
||||
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
@@map("theaters")
|
||||
}
|
||||
17
src/app.module.ts
Normal file
17
src/app.module.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import { Module } from '@nestjs/common'
|
||||
import { ConfigModule } from '@nestjs/config'
|
||||
|
||||
import { PrismaModule } from '@/infra/prisma/prisma.module'
|
||||
|
||||
import { TheaterModule } from './modules/theater/infra/theater.module'
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
ConfigModule.forRoot({
|
||||
isGlobal: true
|
||||
}),
|
||||
PrismaModule,
|
||||
TheaterModule
|
||||
]
|
||||
})
|
||||
export class AppModule {}
|
||||
10
src/infra/prisma/prisma.module.ts
Normal file
10
src/infra/prisma/prisma.module.ts
Normal file
@ -0,0 +1,10 @@
|
||||
import { Global, Module } from '@nestjs/common'
|
||||
|
||||
import { PrismaService } from './prisma.service'
|
||||
|
||||
@Global()
|
||||
@Module({
|
||||
providers: [PrismaService],
|
||||
exports: [PrismaService]
|
||||
})
|
||||
export class PrismaModule {}
|
||||
59
src/infra/prisma/prisma.service.ts
Normal file
59
src/infra/prisma/prisma.service.ts
Normal file
@ -0,0 +1,59 @@
|
||||
import {
|
||||
Injectable,
|
||||
Logger,
|
||||
OnModuleDestroy,
|
||||
OnModuleInit
|
||||
} from '@nestjs/common'
|
||||
import { ConfigService } from '@nestjs/config'
|
||||
import { PrismaPg } from '@prisma/adapter-pg'
|
||||
import { PrismaClient } from '@prisma/generated/client'
|
||||
|
||||
@Injectable()
|
||||
export class PrismaService
|
||||
extends PrismaClient
|
||||
implements OnModuleInit, OnModuleDestroy
|
||||
{
|
||||
private readonly logger = new Logger(PrismaService.name)
|
||||
|
||||
public constructor(private readonly configService: ConfigService) {
|
||||
super({
|
||||
adapter: new PrismaPg({
|
||||
user: configService.getOrThrow('DATABASE_USERNAME'),
|
||||
password: configService.getOrThrow('DATABASE_PASSWORD'),
|
||||
host: configService.getOrThrow('DATABASE_HOST'),
|
||||
port: configService.getOrThrow('DATABASE_PORT'),
|
||||
database: configService.getOrThrow('DATABASE_NAME')
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
public async onModuleInit() {
|
||||
const start = Date.now()
|
||||
|
||||
this.logger.log('Prisma connecting...')
|
||||
|
||||
try {
|
||||
await this.$connect()
|
||||
|
||||
const ms = Date.now() - start
|
||||
|
||||
this.logger.log(`Prisma connected in ${ms}ms`)
|
||||
} catch (e) {
|
||||
this.logger.error('Prisma connection error ', e)
|
||||
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
public async onModuleDestroy() {
|
||||
this.logger.log('Prisma disconnecting...')
|
||||
|
||||
try {
|
||||
await this.$disconnect()
|
||||
|
||||
this.logger.log('Prisma disconnected')
|
||||
} catch (e) {
|
||||
this.logger.error('Prisma disconnection error ', e)
|
||||
}
|
||||
}
|
||||
}
|
||||
35
src/main.ts
Normal file
35
src/main.ts
Normal file
@ -0,0 +1,35 @@
|
||||
import { ConfigService } from '@nestjs/config'
|
||||
import { NestFactory } from '@nestjs/core'
|
||||
import { MicroserviceOptions, Transport } from '@nestjs/microservices'
|
||||
import { PROTO_PATHS } from '@teacinema/contracts'
|
||||
|
||||
import { AppModule } from './app.module'
|
||||
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create(AppModule)
|
||||
|
||||
const config = app.get(ConfigService)
|
||||
const host = config.getOrThrow<string>('GRPC_HOST')
|
||||
const port = config.getOrThrow<string>('GRPC_PORT')
|
||||
const url = `${host}:${port}`
|
||||
|
||||
app.connectMicroservice<MicroserviceOptions>({
|
||||
transport: Transport.GRPC,
|
||||
options: {
|
||||
url,
|
||||
package: ['theater.v1'],
|
||||
protoPath: [PROTO_PATHS.THEATER],
|
||||
loader: {
|
||||
keepCase: false,
|
||||
longs: String,
|
||||
enums: String,
|
||||
defaults: true,
|
||||
oneofs: true
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
await app.startAllMicroservices()
|
||||
await app.init()
|
||||
}
|
||||
bootstrap()
|
||||
@ -0,0 +1,13 @@
|
||||
import { Injectable } from '@nestjs/common'
|
||||
|
||||
import { TheaterEntity } from '../../domain/entities/theater.entity'
|
||||
import { TheaterRepositoryPort } from '../../domain/ports/theater.repository.port'
|
||||
|
||||
@Injectable()
|
||||
export class CreateTheaterUsecase {
|
||||
public constructor(private readonly repository: TheaterRepositoryPort) {}
|
||||
|
||||
public execute(data: Pick<TheaterEntity, 'name' | 'address'>) {
|
||||
return this.repository.create(data)
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
import { Injectable } from '@nestjs/common'
|
||||
import { RpcException } from '@nestjs/microservices'
|
||||
import { RpcStatus } from '@teacinema/common'
|
||||
|
||||
import { TheaterEntity } from '../../domain/entities/theater.entity'
|
||||
import { TheaterRepositoryPort } from '../../domain/ports/theater.repository.port'
|
||||
|
||||
@Injectable()
|
||||
export class GetTheaterUsecase {
|
||||
public constructor(private readonly repository: TheaterRepositoryPort) {}
|
||||
|
||||
public async execute(id: TheaterEntity['id']) {
|
||||
const theater = await this.repository.findById(id)
|
||||
|
||||
if (!theater) {
|
||||
throw new RpcException({
|
||||
code: RpcStatus.NOT_FOUND,
|
||||
message: 'Theater not found'
|
||||
})
|
||||
}
|
||||
|
||||
return theater
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
import { Injectable } from '@nestjs/common'
|
||||
|
||||
import { TheaterRepositoryPort } from '../../domain/ports/theater.repository.port'
|
||||
|
||||
@Injectable()
|
||||
export class ListTheaterUsecase {
|
||||
public constructor(private readonly repository: TheaterRepositoryPort) {}
|
||||
|
||||
public execute() {
|
||||
return this.repository.findAll()
|
||||
}
|
||||
}
|
||||
10
src/modules/theater/domain/entities/theater.entity.ts
Normal file
10
src/modules/theater/domain/entities/theater.entity.ts
Normal file
@ -0,0 +1,10 @@
|
||||
export class TheaterEntity {
|
||||
public constructor(
|
||||
public readonly id: string,
|
||||
public readonly name: string,
|
||||
public readonly address: string,
|
||||
public readonly createdAt: Date,
|
||||
public readonly updatedAt: Date
|
||||
) {}
|
||||
|
||||
}
|
||||
13
src/modules/theater/domain/ports/theater.repository.port.ts
Normal file
13
src/modules/theater/domain/ports/theater.repository.port.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import { TheaterEntity } from '../entities/theater.entity'
|
||||
|
||||
export abstract class TheaterRepositoryPort {
|
||||
public abstract findAll(): Promise<TheaterEntity[]>
|
||||
|
||||
public abstract findById(
|
||||
id: TheaterEntity['id']
|
||||
): Promise<TheaterEntity | null>
|
||||
|
||||
public abstract create(
|
||||
data: Pick<TheaterEntity, 'name' | 'address'>
|
||||
): Promise<TheaterEntity>
|
||||
}
|
||||
@ -0,0 +1,46 @@
|
||||
import { Injectable } from '@nestjs/common'
|
||||
import { Pick } from '@prisma/client/runtime/client'
|
||||
import { Theater } from '@prisma/generated/client'
|
||||
|
||||
import { PrismaService } from '@/infra/prisma/prisma.service'
|
||||
import { TheaterEntity } from '@/modules/theater/domain/entities/theater.entity'
|
||||
|
||||
import { TheaterRepositoryPort } from '../../domain/ports/theater.repository.port'
|
||||
|
||||
@Injectable()
|
||||
export class TheaterPrismaRepository implements TheaterRepositoryPort {
|
||||
public constructor(private readonly prismaService: PrismaService) {}
|
||||
|
||||
public async create(
|
||||
data: Pick<TheaterEntity, 'name' | 'address'>
|
||||
): Promise<TheaterEntity> {
|
||||
const t = await this.prismaService.theater.create({ data })
|
||||
return this.toEntity(t)
|
||||
}
|
||||
|
||||
public async findAll(): Promise<TheaterEntity[]> {
|
||||
const items = await this.prismaService.theater.findMany({
|
||||
orderBy: { name: 'asc' }
|
||||
})
|
||||
return items.map(t => this.toEntity(t))
|
||||
}
|
||||
|
||||
public async findById(
|
||||
id: TheaterEntity['id']
|
||||
): Promise<TheaterEntity | null> {
|
||||
const theater = await this.prismaService.theater.findUnique({
|
||||
where: { id }
|
||||
})
|
||||
return theater ? this.toEntity(theater) : null
|
||||
}
|
||||
|
||||
private toEntity(theater: Theater): TheaterEntity {
|
||||
return new TheaterEntity(
|
||||
theater.id,
|
||||
theater.name,
|
||||
theater.address,
|
||||
theater.createdAt,
|
||||
theater.updatedAt
|
||||
)
|
||||
}
|
||||
}
|
||||
25
src/modules/theater/infra/theater.module.ts
Normal file
25
src/modules/theater/infra/theater.module.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import { Module } from '@nestjs/common'
|
||||
|
||||
import { PrismaModule } from '@/infra/prisma/prisma.module'
|
||||
|
||||
import { CreateTheaterUsecase } from '../applications/commands/create-theater.usecase'
|
||||
import { GetTheaterUsecase } from '../applications/queries/get-theater.usecase'
|
||||
import { ListTheaterUsecase } from '../applications/queries/list-theater.usecase'
|
||||
import { TheaterRepositoryPort } from '../domain/ports/theater.repository.port'
|
||||
import { TheaterGrpcController } from '../interfaces/grpc/theater.grpc.controller'
|
||||
|
||||
import { TheaterPrismaRepository } from './prisma/theater.prisma.repository'
|
||||
|
||||
@Module({
|
||||
controllers: [TheaterGrpcController],
|
||||
providers: [
|
||||
{
|
||||
provide: TheaterRepositoryPort,
|
||||
useClass: TheaterPrismaRepository
|
||||
},
|
||||
ListTheaterUsecase,
|
||||
GetTheaterUsecase,
|
||||
CreateTheaterUsecase
|
||||
]
|
||||
})
|
||||
export class TheaterModule {}
|
||||
@ -0,0 +1,43 @@
|
||||
import { Controller } from '@nestjs/common'
|
||||
import { GrpcMethod } from '@nestjs/microservices'
|
||||
import type {
|
||||
CreateTheaterRequest,
|
||||
CreateTheaterResponse,
|
||||
GetTheaterRequest,
|
||||
GetTheaterResponse,
|
||||
ListTheaterResponse
|
||||
} from '@teacinema/contracts/gen/ts/theater'
|
||||
|
||||
import { CreateTheaterUsecase } from '@/modules/theater/applications/commands/create-theater.usecase'
|
||||
import { GetTheaterUsecase } from '@/modules/theater/applications/queries/get-theater.usecase'
|
||||
|
||||
import { ListTheaterUsecase } from '../../applications/queries/list-theater.usecase'
|
||||
|
||||
@Controller()
|
||||
export class TheaterGrpcController {
|
||||
public constructor(
|
||||
private readonly listUC: ListTheaterUsecase,
|
||||
private readonly gettUC: GetTheaterUsecase,
|
||||
private readonly createUC: CreateTheaterUsecase
|
||||
) {}
|
||||
|
||||
@GrpcMethod('TheaterService', 'ListTheater')
|
||||
public async getAll(): Promise<ListTheaterResponse> {
|
||||
const theaters = await this.listUC.execute()
|
||||
return { theaters }
|
||||
}
|
||||
|
||||
@GrpcMethod('TheaterService', 'GetTheater')
|
||||
public async getById(data: GetTheaterRequest): Promise<GetTheaterResponse> {
|
||||
const theater = await this.gettUC.execute(data.id)
|
||||
return { theater }
|
||||
}
|
||||
|
||||
@GrpcMethod('TheaterService', 'CreateTheater')
|
||||
public async create(
|
||||
data: CreateTheaterRequest
|
||||
): Promise<CreateTheaterResponse> {
|
||||
const theater = await this.createUC.execute(data)
|
||||
return { theater }
|
||||
}
|
||||
}
|
||||
4
tsconfig.build.json
Normal file
4
tsconfig.build.json
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"exclude": ["node_modules", "test", "dist", "prisma", "**/*spec.ts"]
|
||||
}
|
||||
30
tsconfig.json
Normal file
30
tsconfig.json
Normal file
@ -0,0 +1,30 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "nodenext",
|
||||
"moduleResolution": "nodenext",
|
||||
"resolvePackageJsonExports": true,
|
||||
"esModuleInterop": true,
|
||||
"isolatedModules": true,
|
||||
"declaration": true,
|
||||
"removeComments": true,
|
||||
"emitDecoratorMetadata": true,
|
||||
"experimentalDecorators": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"target": "ES2023",
|
||||
"sourceMap": true,
|
||||
"outDir": "./dist",
|
||||
"baseUrl": "./",
|
||||
"incremental": true,
|
||||
"skipLibCheck": true,
|
||||
"strictNullChecks": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"noImplicitAny": false,
|
||||
"strictBindCallApply": false,
|
||||
"noFallthroughCasesInSwitch": false,
|
||||
"paths": {
|
||||
"@/*": ["src/*"],
|
||||
"@prisma/generated": ["./prisma/generated"],
|
||||
"@prisma/generated/*": ["./prisma/generated/*"]
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user