initial commit
This commit is contained in:
commit
b2571955e0
25
.eslintrc.js
Normal file
25
.eslintrc.js
Normal file
@ -0,0 +1,25 @@
|
||||
module.exports = {
|
||||
parser: '@typescript-eslint/parser',
|
||||
parserOptions: {
|
||||
project: 'tsconfig.json',
|
||||
tsconfigRootDir: __dirname,
|
||||
sourceType: 'module',
|
||||
},
|
||||
plugins: ['@typescript-eslint/eslint-plugin'],
|
||||
extends: [
|
||||
'plugin:@typescript-eslint/recommended',
|
||||
'plugin:prettier/recommended',
|
||||
],
|
||||
root: true,
|
||||
env: {
|
||||
node: true,
|
||||
jest: true,
|
||||
},
|
||||
ignorePatterns: ['.eslintrc.js'],
|
||||
rules: {
|
||||
'@typescript-eslint/interface-name-prefix': 'off',
|
||||
'@typescript-eslint/explicit-function-return-type': 'off',
|
||||
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
||||
'@typescript-eslint/no-explicit-any': 'off',
|
||||
},
|
||||
};
|
56
.gitignore
vendored
Normal file
56
.gitignore
vendored
Normal file
@ -0,0 +1,56 @@
|
||||
# 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
|
8
.prettierrc
Normal file
8
.prettierrc
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"singleQuote": true,
|
||||
"trailingComma": "all",
|
||||
"printWidth": 80,
|
||||
"tabWidth": 2,
|
||||
"endOfLine": "lf",
|
||||
"semi": "false"
|
||||
}
|
12
Dockerfile
Normal file
12
Dockerfile
Normal file
@ -0,0 +1,12 @@
|
||||
FROM node:lts-alpine
|
||||
|
||||
WORKDIR /app/
|
||||
|
||||
RUN chown node .
|
||||
COPY --chown=node:node package.json package-lock.json ./
|
||||
COPY --chown=node:node . .
|
||||
USER root
|
||||
RUN npm install
|
||||
ENV TZ=Europe/Budapest
|
||||
|
||||
CMD npm run start:dev
|
73
README.md
Normal file
73
README.md
Normal file
@ -0,0 +1,73 @@
|
||||
<p align="center">
|
||||
<a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="200" 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://coveralls.io/github/nestjs/nest?branch=master" target="_blank"><img src="https://coveralls.io/repos/github/nestjs/nest/badge.svg?branch=master#9" alt="Coverage" /></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"/></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"></a>
|
||||
</p>
|
||||
<!--[](https://opencollective.com/nest#backer)
|
||||
[](https://opencollective.com/nest#sponsor)-->
|
||||
|
||||
## Description
|
||||
|
||||
[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository.
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
$ npm install
|
||||
```
|
||||
|
||||
## Running the app
|
||||
|
||||
```bash
|
||||
# development
|
||||
$ npm run start
|
||||
|
||||
# watch mode
|
||||
$ npm run start:dev
|
||||
|
||||
# production mode
|
||||
$ npm run start:prod
|
||||
```
|
||||
|
||||
## Test
|
||||
|
||||
```bash
|
||||
# unit tests
|
||||
$ npm run test
|
||||
|
||||
# e2e tests
|
||||
$ npm run test:e2e
|
||||
|
||||
# test coverage
|
||||
$ npm run test:cov
|
||||
```
|
||||
|
||||
## 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://kamilmysliwiec.com)
|
||||
- Website - [https://nestjs.com](https://nestjs.com/)
|
||||
- Twitter - [@nestframework](https://twitter.com/nestframework)
|
||||
|
||||
## License
|
||||
|
||||
Nest is [MIT licensed](LICENSE).
|
23
biome.json
Normal file
23
biome.json
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"formatter": {
|
||||
"enabled": true,
|
||||
"formatWithErrors": true,
|
||||
"indentStyle": "space",
|
||||
"indentWidth": 2,
|
||||
"lineWidth": 80,
|
||||
"lineEnding": "lf",
|
||||
"ignore": []
|
||||
},
|
||||
"javascript": {
|
||||
"formatter": {
|
||||
"quoteStyle": "single",
|
||||
"arrowParentheses":"always",
|
||||
"jsxQuoteStyle": "double",
|
||||
"semicolons": "asNeeded",
|
||||
"trailingComma": "all",
|
||||
"quoteProperties": "asNeeded",
|
||||
"bracketSpacing": true,
|
||||
"bracketSameLine": false
|
||||
}
|
||||
}
|
||||
}
|
75
docker-compose.yml
Normal file
75
docker-compose.yml
Normal file
@ -0,0 +1,75 @@
|
||||
version: "3.9"
|
||||
|
||||
services:
|
||||
backend:
|
||||
container_name: photodoc-backend
|
||||
build:
|
||||
context: ../backend/
|
||||
image: photodoc-backend
|
||||
volumes:
|
||||
- ../backend/:/app
|
||||
- /app/node_modules
|
||||
env_file:
|
||||
- ./env/backend.dev.env
|
||||
depends_on:
|
||||
- database
|
||||
ports:
|
||||
- "4000:3000"
|
||||
|
||||
frontend:
|
||||
container_name: photodoc-frontend
|
||||
build:
|
||||
context: ../frontend/
|
||||
image: photodoc-frontend
|
||||
volumes:
|
||||
- ../frontend/:/app
|
||||
- /app/node_modules
|
||||
env_file:
|
||||
- ./env/frontend.dev.env
|
||||
depends_on:
|
||||
- backend
|
||||
ports:
|
||||
- "4005:3000"
|
||||
|
||||
mongo-express:
|
||||
container_name: photodoc-mongo-express
|
||||
image: mongo-express
|
||||
env_file:
|
||||
- ./env/mongo-express.dev.env
|
||||
depends_on:
|
||||
- database
|
||||
ports:
|
||||
- "4010:8081"
|
||||
|
||||
database:
|
||||
container_name: photodoc-mongodb
|
||||
image: mongo
|
||||
volumes:
|
||||
- ./init.js:/docker-entrypoint-initdb.d/init.js
|
||||
- mongo-data:/data/db
|
||||
env_file:
|
||||
- ./env/database.dev.env
|
||||
ports:
|
||||
- "27018:27017"
|
||||
|
||||
ldap-dev:
|
||||
container_name: photodoc-ldap-dev
|
||||
build:
|
||||
context: ./ldap-dev
|
||||
env_file:
|
||||
- ./env/ldap.dev.env
|
||||
|
||||
solr:
|
||||
container_name: photodoc-solr
|
||||
image: solr:9.0.0
|
||||
ports:
|
||||
- "8983:8983"
|
||||
volumes:
|
||||
- solr-data:/var/solr
|
||||
command:
|
||||
- solr-precreate
|
||||
- fotodoc
|
||||
|
||||
volumes:
|
||||
solr-data:
|
||||
mongo-data:
|
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
|
||||
}
|
||||
}
|
9662
package-lock.json
generated
Normal file
9662
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
79
package.json
Normal file
79
package.json
Normal file
@ -0,0 +1,79 @@
|
||||
{
|
||||
"name": "photodoc",
|
||||
"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": {
|
||||
"@nestjs/common": "^10.0.0",
|
||||
"@nestjs/config": "^3.2.0",
|
||||
"@nestjs/core": "^10.0.0",
|
||||
"@nestjs/jwt": "^10.2.0",
|
||||
"@nestjs/mapped-types": "^2.0.5",
|
||||
"@nestjs/mongoose": "^10.0.4",
|
||||
"@nestjs/platform-express": "^10.0.0",
|
||||
"@types/bcrypt": "^5.0.2",
|
||||
"bcrypt": "^5.1.1",
|
||||
"class-transformer": "^0.5.1",
|
||||
"class-validator": "^0.14.1",
|
||||
"ldapts": "^7.0.10",
|
||||
"mongoose": "^8.2.2",
|
||||
"reflect-metadata": "^0.2.0",
|
||||
"rxjs": "^7.8.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@nestjs/cli": "^10.0.0",
|
||||
"@nestjs/schematics": "^10.0.0",
|
||||
"@nestjs/testing": "^10.0.0",
|
||||
"@types/express": "^4.17.17",
|
||||
"@types/jest": "^29.5.2",
|
||||
"@types/node": "^20.3.1",
|
||||
"@types/supertest": "^6.0.0",
|
||||
"@typescript-eslint/eslint-plugin": "^6.0.0",
|
||||
"@typescript-eslint/parser": "^6.0.0",
|
||||
"eslint": "^8.42.0",
|
||||
"eslint-config-prettier": "^9.0.0",
|
||||
"eslint-plugin-prettier": "^5.0.0",
|
||||
"jest": "^29.5.0",
|
||||
"prettier": "^3.0.0",
|
||||
"source-map-support": "^0.5.21",
|
||||
"supertest": "^6.3.3",
|
||||
"ts-jest": "^29.1.0",
|
||||
"ts-loader": "^9.4.3",
|
||||
"ts-node": "^10.9.1",
|
||||
"tsconfig-paths": "^4.2.0",
|
||||
"typescript": "^5.1.3"
|
||||
},
|
||||
"jest": {
|
||||
"moduleFileExtensions": [
|
||||
"js",
|
||||
"json",
|
||||
"ts"
|
||||
],
|
||||
"rootDir": "src",
|
||||
"testRegex": ".*\\.spec\\.ts$",
|
||||
"transform": {
|
||||
"^.+\\.(t|j)s$": "ts-jest"
|
||||
},
|
||||
"collectCoverageFrom": [
|
||||
"**/*.(t|j)s"
|
||||
],
|
||||
"coverageDirectory": "../coverage",
|
||||
"testEnvironment": "node"
|
||||
}
|
||||
}
|
6583
pnpm-lock.yaml
generated
Normal file
6583
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
20
src/announcements/announcements.controller.spec.ts
Normal file
20
src/announcements/announcements.controller.spec.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { AnnouncementsController } from './announcements.controller';
|
||||
import { AnnouncementsService } from './announcements.service';
|
||||
|
||||
describe('AnnouncementsController', () => {
|
||||
let controller: AnnouncementsController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [AnnouncementsController],
|
||||
providers: [AnnouncementsService],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<AnnouncementsController>(AnnouncementsController);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
});
|
45
src/announcements/announcements.controller.ts
Normal file
45
src/announcements/announcements.controller.ts
Normal file
@ -0,0 +1,45 @@
|
||||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Post,
|
||||
Body,
|
||||
Patch,
|
||||
Param,
|
||||
Delete,
|
||||
} from '@nestjs/common'
|
||||
import { AnnouncementsService } from './announcements.service'
|
||||
import { CreateAnnouncementDto } from './dto/create-announcement.dto'
|
||||
import { UpdateAnnouncementDto } from './dto/update-announcement.dto'
|
||||
|
||||
@Controller('announcements')
|
||||
export class AnnouncementsController {
|
||||
constructor(private readonly announcementsService: AnnouncementsService) {}
|
||||
|
||||
@Post()
|
||||
create(@Body() createAnnouncementDto: CreateAnnouncementDto) {
|
||||
return this.announcementsService.create(createAnnouncementDto);
|
||||
}
|
||||
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.announcementsService.findAll()
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: string) {
|
||||
return this.announcementsService.findOne(id);
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
update(
|
||||
@Param('id') id: string,
|
||||
@Body() updateAnnouncementDto: UpdateAnnouncementDto,
|
||||
) {
|
||||
return this.announcementsService.update(id, updateAnnouncementDto)
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
remove(@Param('id') id: string) {
|
||||
return this.announcementsService.remove(id);
|
||||
}
|
||||
}
|
9
src/announcements/announcements.module.ts
Normal file
9
src/announcements/announcements.module.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { AnnouncementsService } from './announcements.service';
|
||||
import { AnnouncementsController } from './announcements.controller';
|
||||
|
||||
@Module({
|
||||
controllers: [AnnouncementsController],
|
||||
providers: [AnnouncementsService],
|
||||
})
|
||||
export class AnnouncementsModule {}
|
18
src/announcements/announcements.service.spec.ts
Normal file
18
src/announcements/announcements.service.spec.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { AnnouncementsService } from './announcements.service';
|
||||
|
||||
describe('AnnouncementsService', () => {
|
||||
let service: AnnouncementsService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [AnnouncementsService],
|
||||
}).compile();
|
||||
|
||||
service = module.get<AnnouncementsService>(AnnouncementsService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
26
src/announcements/announcements.service.ts
Normal file
26
src/announcements/announcements.service.ts
Normal file
@ -0,0 +1,26 @@
|
||||
import { Injectable } from '@nestjs/common'
|
||||
import { CreateAnnouncementDto } from './dto/create-announcement.dto'
|
||||
import { UpdateAnnouncementDto } from './dto/update-announcement.dto'
|
||||
|
||||
@Injectable()
|
||||
export class AnnouncementsService {
|
||||
create(createAnnouncementDto: CreateAnnouncementDto) {
|
||||
return 'This action adds a new announcement'
|
||||
}
|
||||
|
||||
findAll() {
|
||||
return `This action returns all announcements`
|
||||
}
|
||||
|
||||
findOne(id: string) {
|
||||
return `This action returns a #${id} announcement`
|
||||
}
|
||||
|
||||
update(id: string, updateAnnouncementDto: UpdateAnnouncementDto) {
|
||||
return `This action updates a #${id} announcement`
|
||||
}
|
||||
|
||||
remove(id: string) {
|
||||
return `This action removes a #${id} announcement`
|
||||
}
|
||||
}
|
27
src/announcements/dto/create-announcement.dto.ts
Normal file
27
src/announcements/dto/create-announcement.dto.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import { IsNotEmpty, IsOptional, IsString } from 'class-validator'
|
||||
|
||||
export class CreateAnnouncementDto {
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
title: any
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
intro?: string
|
||||
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
paragraph1: string
|
||||
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
paragraph2: string
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
quote?: string
|
||||
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
regards: string
|
||||
}
|
4
src/announcements/dto/update-announcement.dto.ts
Normal file
4
src/announcements/dto/update-announcement.dto.ts
Normal file
@ -0,0 +1,4 @@
|
||||
import { PartialType } from '@nestjs/mapped-types'
|
||||
import { CreateAnnouncementDto } from './create-announcement.dto'
|
||||
|
||||
export class UpdateAnnouncementDto extends PartialType(CreateAnnouncementDto) {}
|
1
src/announcements/entities/announcement.entity.ts
Normal file
1
src/announcements/entities/announcement.entity.ts
Normal file
@ -0,0 +1 @@
|
||||
export class Announcement {}
|
22
src/app.controller.spec.ts
Normal file
22
src/app.controller.spec.ts
Normal file
@ -0,0 +1,22 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing'
|
||||
import { AppController } from './app.controller'
|
||||
import { AppService } from './app.service'
|
||||
|
||||
describe('AppController', () => {
|
||||
let appController: AppController
|
||||
|
||||
beforeEach(async () => {
|
||||
const app: TestingModule = await Test.createTestingModule({
|
||||
controllers: [AppController],
|
||||
providers: [AppService],
|
||||
}).compile()
|
||||
|
||||
appController = app.get<AppController>(AppController)
|
||||
})
|
||||
|
||||
describe('root', () => {
|
||||
it('should return "Hello World!"', () => {
|
||||
expect(appController.getHello()).toBe('Hello World!')
|
||||
})
|
||||
})
|
||||
})
|
14
src/app.controller.ts
Normal file
14
src/app.controller.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import { Controller, Get, UseGuards } from '@nestjs/common'
|
||||
import { AppService } from './app.service'
|
||||
import { AuthGuard } from './auth/auth.guard'
|
||||
|
||||
@Controller()
|
||||
export class AppController {
|
||||
constructor(private readonly appService: AppService) {}
|
||||
|
||||
@UseGuards(AuthGuard)
|
||||
@Get()
|
||||
getHello(): string {
|
||||
return this.appService.getHello()
|
||||
}
|
||||
}
|
36
src/app.module.ts
Normal file
36
src/app.module.ts
Normal file
@ -0,0 +1,36 @@
|
||||
import { Module } from '@nestjs/common'
|
||||
import { AppController } from './app.controller'
|
||||
import { AppService } from './app.service'
|
||||
import { AuthModule } from './auth/auth.module'
|
||||
import { ConfigModule, ConfigService } from '@nestjs/config'
|
||||
import { MongooseModule } from '@nestjs/mongoose'
|
||||
import { UsersModule } from './users/users.module'
|
||||
import { SearchController } from './search/search.controller'
|
||||
import { SearchService } from './search/search.service'
|
||||
import { SearchModule } from './search/search.module'
|
||||
import { EventsModule } from './events/events.module'
|
||||
import { ConnectionsModule } from './connections/connections.module'
|
||||
import { AnnouncementsModule } from './announcements/announcements.module'
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
AuthModule,
|
||||
ConfigModule.forRoot(),
|
||||
MongooseModule.forRootAsync({
|
||||
imports: [ConfigModule],
|
||||
inject: [ConfigService],
|
||||
useFactory: (configService: ConfigService) => ({
|
||||
uri: configService.getOrThrow('MONGO_URI'),
|
||||
}),
|
||||
}),
|
||||
ConfigModule,
|
||||
UsersModule,
|
||||
EventsModule,
|
||||
SearchModule,
|
||||
AnnouncementsModule,
|
||||
ConnectionsModule,
|
||||
],
|
||||
controllers: [AppController, SearchController],
|
||||
providers: [AppService, SearchService],
|
||||
})
|
||||
export class AppModule {}
|
8
src/app.service.ts
Normal file
8
src/app.service.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { Injectable } from '@nestjs/common'
|
||||
|
||||
@Injectable()
|
||||
export class AppService {
|
||||
getHello(): string {
|
||||
return 'Hello World!'
|
||||
}
|
||||
}
|
18
src/auth/auth.controller.spec.ts
Normal file
18
src/auth/auth.controller.spec.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing'
|
||||
import { AuthController } from './auth.controller'
|
||||
|
||||
describe('AuthController', () => {
|
||||
let controller: AuthController
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [AuthController],
|
||||
}).compile()
|
||||
|
||||
controller = module.get<AuthController>(AuthController)
|
||||
})
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined()
|
||||
})
|
||||
})
|
18
src/auth/auth.controller.ts
Normal file
18
src/auth/auth.controller.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import { Body, Controller, Post } from '@nestjs/common'
|
||||
import { AuthService } from './auth.service'
|
||||
import { RegisterDto } from './dto/register.dto'
|
||||
import { LoginDto } from './dto/login.dto'
|
||||
|
||||
@Controller('auth')
|
||||
export class AuthController {
|
||||
constructor(private authService: AuthService) {}
|
||||
@Post("register")
|
||||
register(@Body() body: RegisterDto) {
|
||||
return this.authService.register(body);
|
||||
}
|
||||
|
||||
@Post('login')
|
||||
login(@Body() body: LoginDto) {
|
||||
return this.authService.login(body)
|
||||
}
|
||||
}
|
41
src/auth/auth.guard.ts
Normal file
41
src/auth/auth.guard.ts
Normal file
@ -0,0 +1,41 @@
|
||||
import {
|
||||
CanActivate,
|
||||
ExecutionContext,
|
||||
Injectable,
|
||||
UnauthorizedException,
|
||||
} from '@nestjs/common'
|
||||
import { ConfigService } from '@nestjs/config'
|
||||
import { JwtService } from '@nestjs/jwt'
|
||||
import { Request } from 'express'
|
||||
|
||||
@Injectable()
|
||||
export class AuthGuard implements CanActivate {
|
||||
constructor(
|
||||
private jwtService: JwtService,
|
||||
private configService: ConfigService,
|
||||
) {}
|
||||
|
||||
async canActivate(context: ExecutionContext): Promise<boolean> {
|
||||
const request = context.switchToHttp().getRequest()
|
||||
const token = this.extractTokenFromHeader(request)
|
||||
if (!token) {
|
||||
throw new UnauthorizedException()
|
||||
}
|
||||
try {
|
||||
const payload = await this.jwtService.verifyAsync(token, {
|
||||
secret: this.configService.getOrThrow('JWT_SECRET'),
|
||||
})
|
||||
// 💡 We're assigning the payload to the request object here
|
||||
// so that we can access it in our route handlers
|
||||
request['user'] = payload
|
||||
} catch {
|
||||
throw new UnauthorizedException()
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
private extractTokenFromHeader(request: Request): string | undefined {
|
||||
const [type, token] = request.headers.authorization?.split(' ') ?? []
|
||||
return type === 'Bearer' ? token : undefined
|
||||
}
|
||||
}
|
27
src/auth/auth.module.ts
Normal file
27
src/auth/auth.module.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import { Module } from '@nestjs/common'
|
||||
import { AuthController } from './auth.controller'
|
||||
import { AuthService } from './auth.service'
|
||||
import { JwtModule } from '@nestjs/jwt'
|
||||
import { ConfigModule, ConfigService } from '@nestjs/config'
|
||||
import { MongooseModule } from '@nestjs/mongoose'
|
||||
import { User, UserSchema } from 'src/schemas/user.schema'
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
ConfigModule,
|
||||
JwtModule.registerAsync({
|
||||
global: true,
|
||||
imports: [ConfigModule],
|
||||
inject: [ConfigService],
|
||||
useFactory: (config: ConfigService) => ({
|
||||
global: true,
|
||||
secret: config.getOrThrow('JWT_SECRET'),
|
||||
signOptions: { expiresIn: '600s' },
|
||||
}),
|
||||
}),
|
||||
MongooseModule.forFeature([{ name: User.name, schema: UserSchema }]),
|
||||
],
|
||||
controllers: [AuthController],
|
||||
providers: [AuthService],
|
||||
})
|
||||
export class AuthModule {}
|
18
src/auth/auth.service.spec.ts
Normal file
18
src/auth/auth.service.spec.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing'
|
||||
import { AuthService } from './auth.service'
|
||||
|
||||
describe('AuthService', () => {
|
||||
let service: AuthService
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [AuthService],
|
||||
}).compile()
|
||||
|
||||
service = module.get<AuthService>(AuthService)
|
||||
})
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined()
|
||||
})
|
||||
})
|
77
src/auth/auth.service.ts
Normal file
77
src/auth/auth.service.ts
Normal file
@ -0,0 +1,77 @@
|
||||
import {
|
||||
Injectable,
|
||||
InternalServerErrorException,
|
||||
Logger,
|
||||
NotFoundException,
|
||||
UnauthorizedException,
|
||||
} from '@nestjs/common'
|
||||
import { JwtService } from '@nestjs/jwt'
|
||||
import { InjectModel } from '@nestjs/mongoose'
|
||||
import { Model } from 'mongoose'
|
||||
import { User } from 'src/schemas/user.schema'
|
||||
import bcrypt from 'bcrypt'
|
||||
import { RegisterDto } from './dto/register.dto'
|
||||
import { LoginDto } from './dto/login.dto'
|
||||
import { randomUUID } from 'crypto'
|
||||
import { ConfirmDto } from './dto/confirm.dto'
|
||||
import { UpdatePasswordDto } from './dto/update-password.dto'
|
||||
|
||||
@Injectable()
|
||||
export class AuthService {
|
||||
private readonly logger = new Logger(AuthService.name);
|
||||
|
||||
constructor(
|
||||
@InjectModel(User.name) private userModel: Model<User>,
|
||||
private jwtService: JwtService,
|
||||
) {}
|
||||
|
||||
async login(body: LoginDto): Promise<{ token: string }> {
|
||||
const user = await this.userModel.findOne({ email: body.email })
|
||||
|
||||
if (!user) throw new UnauthorizedException('wrong credentials')
|
||||
|
||||
if (!(await bcrypt.compare(body.password, user.password)))
|
||||
throw new UnauthorizedException('wrong credentials')
|
||||
|
||||
return { token: this.jwtService.sign(user.email) }
|
||||
}
|
||||
|
||||
async register(body: RegisterDto) {
|
||||
try {
|
||||
const hashedPassword = await bcrypt.hash(body.password, 10)
|
||||
|
||||
await this.userModel.create({
|
||||
...body,
|
||||
password: hashedPassword,
|
||||
registrationToken: randomUUID(),
|
||||
})
|
||||
} catch (err) {
|
||||
this.logger.error('Could not register user', err)
|
||||
throw new InternalServerErrorException()
|
||||
}
|
||||
}
|
||||
|
||||
async confirmRegistration(body: ConfirmDto) {
|
||||
const user = await this.userModel.findById(body.id)
|
||||
|
||||
if (!user) throw new NotFoundException('user not found')
|
||||
|
||||
if (user.registrationToken != body.token)
|
||||
throw new UnauthorizedException('wrong registration token')
|
||||
|
||||
user.status = 'CONFIRMED'
|
||||
await user.save()
|
||||
}
|
||||
|
||||
async updatePassword(body: UpdatePasswordDto) {
|
||||
const user = await this.userModel.findById(body.id)
|
||||
|
||||
if (!user) throw new NotFoundException('user not found')
|
||||
|
||||
if (!(await bcrypt.compare(body.oldPassword, user.password)))
|
||||
throw new UnauthorizedException('wrong credentials')
|
||||
|
||||
user.password = await bcrypt.hash(body.newPassword, 10)
|
||||
await user.save()
|
||||
}
|
||||
}
|
8
src/auth/auth.types.ts
Normal file
8
src/auth/auth.types.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { IsNotEmpty } from 'class-validator'
|
||||
|
||||
export class LoginUserDto {
|
||||
@IsNotEmpty()
|
||||
username: string
|
||||
@IsNotEmpty()
|
||||
password: string
|
||||
}
|
11
src/auth/dto/confirm.dto.ts
Normal file
11
src/auth/dto/confirm.dto.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import { IsNotEmpty, IsString } from 'class-validator'
|
||||
|
||||
export class ConfirmDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
id: number
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
token: string
|
||||
}
|
11
src/auth/dto/login.dto.ts
Normal file
11
src/auth/dto/login.dto.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import { IsNotEmpty, IsString } from 'class-validator'
|
||||
|
||||
export class LoginDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
email: string
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
password: string
|
||||
}
|
35
src/auth/dto/register.dto.ts
Normal file
35
src/auth/dto/register.dto.ts
Normal file
@ -0,0 +1,35 @@
|
||||
import { IsNotEmpty, IsString } from 'class-validator'
|
||||
|
||||
export class RegisterDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
email: string
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
password: string
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
racerName: string
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
firstName: string
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
lastName: string
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
country: string
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
profileType: string
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
birthDate: string
|
||||
}
|
15
src/auth/dto/update-password.dto.ts
Normal file
15
src/auth/dto/update-password.dto.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import { IsNotEmpty, IsString } from 'class-validator'
|
||||
|
||||
export class UpdatePasswordDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
id: number
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
oldPassword: string
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
newPassword: string
|
||||
}
|
9
src/common/dto/pagination.dto.ts
Normal file
9
src/common/dto/pagination.dto.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import { IsNumber } from 'class-validator'
|
||||
|
||||
export class PaginationDto {
|
||||
@IsNumber()
|
||||
page?: number
|
||||
|
||||
@IsNumber()
|
||||
size?: number
|
||||
}
|
20
src/connections/connections.controller.spec.ts
Normal file
20
src/connections/connections.controller.spec.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { ConnectionsController } from './connections.controller';
|
||||
import { ConnectionsService } from './connections.service';
|
||||
|
||||
describe('ConnectionsController', () => {
|
||||
let controller: ConnectionsController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [ConnectionsController],
|
||||
providers: [ConnectionsService],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<ConnectionsController>(ConnectionsController);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
});
|
63
src/connections/connections.controller.ts
Normal file
63
src/connections/connections.controller.ts
Normal file
@ -0,0 +1,63 @@
|
||||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Post,
|
||||
Body,
|
||||
Param,
|
||||
Delete,
|
||||
Headers,
|
||||
} from '@nestjs/common'
|
||||
import { ConnectionsService } from './connections.service'
|
||||
import { CreateConnectionDto } from './dto/create-connection.dto'
|
||||
|
||||
@Controller('connections')
|
||||
export class ConnectionsController {
|
||||
constructor(private readonly connectionsService: ConnectionsService) {}
|
||||
|
||||
// creates a pending request.
|
||||
@Post()
|
||||
create(
|
||||
@Body() createConnectionDto: CreateConnectionDto,
|
||||
@Headers('Authorization') authHeader: string,
|
||||
) {
|
||||
return this.connectionsService.create(authHeader, createConnectionDto)
|
||||
}
|
||||
|
||||
// returns pending connections for the requesting user.
|
||||
@Get()
|
||||
pending(
|
||||
@Headers('Authorization') authHeader: string,
|
||||
) {
|
||||
return this.connectionsService.pending(authHeader)
|
||||
}
|
||||
|
||||
// accepts a recieved connection. returns unauthorized if the requesting user is
|
||||
// not the reciever.
|
||||
@Post(':id')
|
||||
accept(
|
||||
@Headers('Authorization') authHeader: string,
|
||||
@Param('id') id: string,
|
||||
) {
|
||||
return this.connectionsService.accept(authHeader, +id)
|
||||
}
|
||||
|
||||
// declines a recieved connection. returns unauthorized if the requesting user is
|
||||
// not the reciever.
|
||||
@Post(':id')
|
||||
decline(
|
||||
@Headers('Authorization') authHeader: string,
|
||||
@Param('id') id: string,
|
||||
) {
|
||||
return this.connectionsService.decline(authHeader, +id)
|
||||
}
|
||||
|
||||
// deletes a sent connection. returns unauthorized if the requesting user is
|
||||
// not the sender.
|
||||
@Delete(':id')
|
||||
remove(
|
||||
@Headers('Authorization') authHeader: string,
|
||||
@Param('id') id: string,
|
||||
) {
|
||||
return this.connectionsService.remove(authHeader, +id)
|
||||
}
|
||||
}
|
18
src/connections/connections.module.ts
Normal file
18
src/connections/connections.module.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import { Module } from '@nestjs/common'
|
||||
import { ConnectionsService } from './connections.service'
|
||||
import { ConnectionsController } from './connections.controller'
|
||||
import { MongooseModule } from '@nestjs/mongoose'
|
||||
import { Connection, ConnectionSchema } from 'src/schemas/connection.schema'
|
||||
import { User, UserSchema } from 'src/schemas/user.schema'
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
MongooseModule.forFeature([
|
||||
{ name: User.name, schema: UserSchema },
|
||||
{ name: Connection.name, schema: ConnectionSchema },
|
||||
]),
|
||||
],
|
||||
controllers: [ConnectionsController],
|
||||
providers: [ConnectionsService],
|
||||
})
|
||||
export class ConnectionsModule {}
|
18
src/connections/connections.service.spec.ts
Normal file
18
src/connections/connections.service.spec.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { ConnectionsService } from './connections.service';
|
||||
|
||||
describe('ConnectionsService', () => {
|
||||
let service: ConnectionsService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [ConnectionsService],
|
||||
}).compile();
|
||||
|
||||
service = module.get<ConnectionsService>(ConnectionsService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
108
src/connections/connections.service.ts
Normal file
108
src/connections/connections.service.ts
Normal file
@ -0,0 +1,108 @@
|
||||
import {
|
||||
Injectable,
|
||||
NotFoundException,
|
||||
UnauthorizedException,
|
||||
} from '@nestjs/common'
|
||||
import { CreateConnectionDto } from './dto/create-connection.dto'
|
||||
import { UpdateConnectionDto } from './dto/update-connection.dto'
|
||||
import { InjectModel } from '@nestjs/mongoose'
|
||||
import { Model } from 'mongoose'
|
||||
import { JwtService } from '@nestjs/jwt'
|
||||
import { User } from 'src/schemas/user.schema'
|
||||
import { Connection } from 'src/schemas/connection.schema'
|
||||
|
||||
@Injectable()
|
||||
export class ConnectionsService {
|
||||
constructor(
|
||||
@InjectModel(Connection.name) private connectionModel: Model<Connection>,
|
||||
@InjectModel(User.name) private userModel: Model<User>,
|
||||
private jwtService: JwtService,
|
||||
) {}
|
||||
|
||||
// creates a pending request.
|
||||
async create(authHeader: string, createConnectionDto: CreateConnectionDto) {
|
||||
const decodedJwt = this.jwtService.decode(authHeader.split(' ')[1])
|
||||
const userId = decodedJwt.userId
|
||||
|
||||
if (!userId) throw new UnauthorizedException()
|
||||
|
||||
const reciever = await this.userModel.findOne({
|
||||
_id: createConnectionDto.reciever,
|
||||
})
|
||||
|
||||
if (!reciever) throw new NotFoundException()
|
||||
|
||||
return await this.connectionModel.create({
|
||||
sender: userId,
|
||||
reciever: reciever.id,
|
||||
status: 'PENDING',
|
||||
})
|
||||
}
|
||||
|
||||
// returns pending connections for the requesting user.
|
||||
async pending(authHeader: string) {
|
||||
const decodedJwt = this.jwtService.decode(authHeader.split(' ')[1])
|
||||
const userId = decodedJwt.userId
|
||||
|
||||
if (!userId) throw new UnauthorizedException()
|
||||
|
||||
return await this.connectionModel.find({
|
||||
reciever: userId,
|
||||
status: 'PENDING',
|
||||
})
|
||||
}
|
||||
|
||||
// accepts a recieved connection. returns unauthorized if the requesting user is
|
||||
// not the reciever.
|
||||
async accept(authHeader: string, _id: number) {
|
||||
const decodedJwt = this.jwtService.decode(authHeader.split(' ')[1])
|
||||
const userId = decodedJwt.userId
|
||||
|
||||
if (!userId) throw new UnauthorizedException()
|
||||
|
||||
const connection = await this.connectionModel.findOne({ _id })
|
||||
|
||||
if (!connection) throw new NotFoundException()
|
||||
|
||||
if (connection.reciever != userId) throw new UnauthorizedException()
|
||||
|
||||
return await this.connectionModel.findOneAndUpdate(
|
||||
{ _id },
|
||||
{ status: 'ACTIVE' },
|
||||
)
|
||||
}
|
||||
|
||||
// declines a recieved connection. returns unauthorized if the requesting user is
|
||||
// not the reciever.
|
||||
async decline(authHeader: string, _id: number) {
|
||||
const decodedJwt = this.jwtService.decode(authHeader.split(' ')[1])
|
||||
const userId = decodedJwt.userId
|
||||
|
||||
if (!userId) throw new UnauthorizedException()
|
||||
|
||||
const connection = await this.connectionModel.findOne({ _id })
|
||||
|
||||
if (!connection) throw new NotFoundException()
|
||||
|
||||
if (connection.reciever != userId) throw new UnauthorizedException()
|
||||
|
||||
return await this.connectionModel.findOneAndDelete({ _id })
|
||||
}
|
||||
|
||||
// deletes a sent connection. returns unauthorized if the requesting user is
|
||||
// not the sender.
|
||||
async remove(authHeader: string, _id: number) {
|
||||
const decodedJwt = this.jwtService.decode(authHeader.split(' ')[1])
|
||||
const userId = decodedJwt.userId
|
||||
|
||||
if (!userId) throw new UnauthorizedException()
|
||||
|
||||
const connection = await this.connectionModel.findOne({ _id })
|
||||
|
||||
if (!connection) throw new NotFoundException()
|
||||
|
||||
if (connection.sender != userId) throw new UnauthorizedException()
|
||||
|
||||
return await this.connectionModel.findOneAndDelete({ _id })
|
||||
}
|
||||
}
|
7
src/connections/dto/create-connection.dto.ts
Normal file
7
src/connections/dto/create-connection.dto.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import { IsNotEmpty, IsNumber } from 'class-validator'
|
||||
|
||||
export class CreateConnectionDto {
|
||||
@IsNotEmpty()
|
||||
@IsNumber()
|
||||
reciever: number
|
||||
}
|
4
src/connections/dto/update-connection.dto.ts
Normal file
4
src/connections/dto/update-connection.dto.ts
Normal file
@ -0,0 +1,4 @@
|
||||
import { PartialType } from '@nestjs/mapped-types';
|
||||
import { CreateConnectionDto } from './create-connection.dto';
|
||||
|
||||
export class UpdateConnectionDto extends PartialType(CreateConnectionDto) {}
|
48
src/events/dto/create-event.dto.ts
Normal file
48
src/events/dto/create-event.dto.ts
Normal file
@ -0,0 +1,48 @@
|
||||
import { IsDate, IsEnum, IsNotEmpty, IsString } from 'class-validator'
|
||||
import { ChampionshipLevel, EventStatus } from 'src/schemas/event.schema'
|
||||
|
||||
export class CreateEventDto {
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
name: string
|
||||
|
||||
@IsNotEmpty()
|
||||
@IsEnum(EventStatus)
|
||||
status: EventStatus
|
||||
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
description: string
|
||||
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
image: string
|
||||
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
location: string
|
||||
|
||||
@IsNotEmpty()
|
||||
@IsDate() // lehet hogy IsDateString
|
||||
startTime: Date
|
||||
|
||||
@IsNotEmpty()
|
||||
@IsDate() // lehet hogy IsDateString
|
||||
endTime: Date
|
||||
|
||||
@IsNotEmpty()
|
||||
@IsEnum(ChampionshipLevel)
|
||||
championshipLevel: ChampionshipLevel
|
||||
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
category: string
|
||||
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
rosterName: string
|
||||
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
rosterUrl: string
|
||||
}
|
4
src/events/dto/update-event.dto.ts
Normal file
4
src/events/dto/update-event.dto.ts
Normal file
@ -0,0 +1,4 @@
|
||||
import { PartialType } from '@nestjs/mapped-types'
|
||||
import { CreateEventDto } from './create-event.dto'
|
||||
|
||||
export class UpdateEventDto extends PartialType(CreateEventDto) {}
|
18
src/events/events.controller.spec.ts
Normal file
18
src/events/events.controller.spec.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { EventsController } from './events.controller';
|
||||
|
||||
describe('EventsController', () => {
|
||||
let controller: EventsController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [EventsController],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<EventsController>(EventsController);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
});
|
34
src/events/events.controller.ts
Normal file
34
src/events/events.controller.ts
Normal file
@ -0,0 +1,34 @@
|
||||
import { Body, Controller, Delete, Get, Param, Post, Put } from '@nestjs/common'
|
||||
import { EventsService } from './events.service'
|
||||
import { CreateEventDto } from './dto/create-event.dto'
|
||||
import { UpdateEventDto } from './dto/update-event.dto'
|
||||
|
||||
@Controller('events')
|
||||
export class EventsController {
|
||||
constructor(private readonly eventsService: EventsService) {}
|
||||
|
||||
@Post()
|
||||
create(@Body() body: CreateEventDto) {
|
||||
return this.eventsService.create(body)
|
||||
}
|
||||
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.eventsService.findAll()
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: string) {
|
||||
return this.eventsService.findOne(id)
|
||||
}
|
||||
|
||||
@Put(':id')
|
||||
update(@Param('id') id: string, @Body() updateEventDto: UpdateEventDto) {
|
||||
return this.eventsService.update(id, updateEventDto)
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
remove(@Param('id') id: string) {
|
||||
return this.eventsService.remove(id)
|
||||
}
|
||||
}
|
14
src/events/events.module.ts
Normal file
14
src/events/events.module.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import { Module } from '@nestjs/common'
|
||||
import { EventsController } from './events.controller'
|
||||
import { EventsService } from './events.service'
|
||||
import { MongooseModule } from '@nestjs/mongoose'
|
||||
import { EventSchema } from 'src/schemas/event.schema'
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
MongooseModule.forFeature([{ name: Event.name, schema: EventSchema }]),
|
||||
],
|
||||
controllers: [EventsController],
|
||||
providers: [EventsService],
|
||||
})
|
||||
export class EventsModule {}
|
18
src/events/events.service.spec.ts
Normal file
18
src/events/events.service.spec.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { EventsService } from './events.service';
|
||||
|
||||
describe('EventsService', () => {
|
||||
let service: EventsService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [EventsService],
|
||||
}).compile();
|
||||
|
||||
service = module.get<EventsService>(EventsService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
33
src/events/events.service.ts
Normal file
33
src/events/events.service.ts
Normal file
@ -0,0 +1,33 @@
|
||||
import { Injectable } from '@nestjs/common'
|
||||
import { InjectModel } from '@nestjs/mongoose'
|
||||
import { Model } from 'mongoose'
|
||||
import { Event } from 'src/schemas/event.schema'
|
||||
import { CreateEventDto } from './dto/create-event.dto'
|
||||
import { UpdateEventDto } from './dto/update-event.dto'
|
||||
|
||||
@Injectable()
|
||||
export class EventsService {
|
||||
constructor(
|
||||
@InjectModel(Event.name) private eventModel: Model<Event>,
|
||||
) {}
|
||||
|
||||
async create(body: CreateEventDto) {
|
||||
await this.eventModel.create(body)
|
||||
}
|
||||
|
||||
async findAll() {
|
||||
return await this.eventModel.find({})
|
||||
}
|
||||
|
||||
async findOne(_id: string) {
|
||||
return await this.eventModel.findById(_id)
|
||||
}
|
||||
|
||||
async update(_id: string, updateEventDto: UpdateEventDto) {
|
||||
return await this.eventModel.findOneAndUpdate({ _id }, updateEventDto)
|
||||
}
|
||||
|
||||
async remove(_id: string) {
|
||||
return await this.eventModel.deleteOne({ _id })
|
||||
}
|
||||
}
|
10
src/main.ts
Normal file
10
src/main.ts
Normal file
@ -0,0 +1,10 @@
|
||||
import { NestFactory } from '@nestjs/core'
|
||||
import { AppModule } from './app.module'
|
||||
import { ValidationPipe } from '@nestjs/common'
|
||||
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create(AppModule)
|
||||
app.useGlobalPipes(new ValidationPipe())
|
||||
await app.listen(3000)
|
||||
}
|
||||
bootstrap()
|
35
src/schemas/announcement.schema.ts
Normal file
35
src/schemas/announcement.schema.ts
Normal file
@ -0,0 +1,35 @@
|
||||
import { Prop, Schema } from '@nestjs/mongoose'
|
||||
|
||||
// export type Announcement = {
|
||||
// id: string
|
||||
// title: any
|
||||
// intro?: string
|
||||
// paragraph1: string
|
||||
// paragraph2: string
|
||||
// quote?: string
|
||||
// regards: string
|
||||
// }
|
||||
|
||||
@Schema()
|
||||
export class Announcement {
|
||||
@Prop({ required: true })
|
||||
name: string
|
||||
|
||||
@Prop()
|
||||
title: any
|
||||
|
||||
@Prop()
|
||||
intro?: string
|
||||
|
||||
@Prop()
|
||||
paragraph1: string
|
||||
|
||||
@Prop()
|
||||
paragraph2: string
|
||||
|
||||
@Prop()
|
||||
quote?: string
|
||||
|
||||
@Prop()
|
||||
regards: string
|
||||
}
|
52
src/schemas/connection.schema.ts
Normal file
52
src/schemas/connection.schema.ts
Normal file
@ -0,0 +1,52 @@
|
||||
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'
|
||||
import mongoose, { HydratedDocument } from 'mongoose'
|
||||
import { User } from './user.schema'
|
||||
|
||||
export type ConnectionDocument = HydratedDocument<Connection>
|
||||
|
||||
export type ConnectionStatus = 'PENDING' | 'ACTIVE'
|
||||
|
||||
// export type Userr = {
|
||||
// id: number;
|
||||
// profileType: {
|
||||
// id: number;
|
||||
// name: string;
|
||||
// };
|
||||
// email: string;
|
||||
// country: {
|
||||
// id: number;
|
||||
// name: string;
|
||||
// languageKey: keyof typeof countries;
|
||||
// };
|
||||
// status: RegistrationStatus;
|
||||
// profilePic?: string;
|
||||
// description?: string;
|
||||
// contacts?: string;
|
||||
// birthDate: string;
|
||||
// firstName: string;
|
||||
// lastName: string;
|
||||
// racerName: string;
|
||||
// interests?: UserInterestDTO[];
|
||||
// socialLinks?: SocialLinkDTO[];
|
||||
// sponsors?: SponsorDTO[];
|
||||
// }
|
||||
|
||||
@Schema()
|
||||
export class Connection {
|
||||
@Prop({
|
||||
required: true,
|
||||
type: { type: mongoose.Schema.Types.ObjectId, ref: 'User' },
|
||||
})
|
||||
sender: User
|
||||
|
||||
@Prop({
|
||||
required: true,
|
||||
type: { type: mongoose.Schema.Types.ObjectId, ref: 'User' },
|
||||
})
|
||||
reciever: User
|
||||
|
||||
@Prop({ required: true, enum: ['PENDING', 'ACTIVE'] })
|
||||
status: ConnectionStatus
|
||||
}
|
||||
|
||||
export const ConnectionSchema = SchemaFactory.createForClass(User)
|
97
src/schemas/event.schema.ts
Normal file
97
src/schemas/event.schema.ts
Normal file
@ -0,0 +1,97 @@
|
||||
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'
|
||||
import { HydratedDocument } from 'mongoose'
|
||||
|
||||
export type EventDocument = HydratedDocument<Event>
|
||||
// export type EventStatus = 'ACTIVE' | 'POSTPONED' | 'CANCELLED' | 'FINISHED'
|
||||
export enum EventStatus {
|
||||
ACTIVE = 'ACTIVE',
|
||||
POSTPONED = 'POSTPONED',
|
||||
CANCELLED = 'CANCELLED',
|
||||
FINISHED = 'FINISHED',
|
||||
}
|
||||
|
||||
// export type ChampionshipLevel =
|
||||
// | 'WORLD'
|
||||
// | 'CONTINENTAL'
|
||||
// | 'INTERNATIONAL'
|
||||
// | 'NATIONAL'
|
||||
// | 'AMATEUR'
|
||||
|
||||
export enum ChampionshipLevel {
|
||||
WORLD = 'WORLD',
|
||||
CONTINENTAL = 'CONTINENTAL',
|
||||
INTERNATIONAL = 'INTERNATIONAL',
|
||||
NATIONAL = 'NATIONAL',
|
||||
AMATEUR = 'AMATEUR',
|
||||
}
|
||||
|
||||
export type EventCategory = 'CAR' | 'BIKE' | 'PLANE' | 'BOAT' | 'RC' | 'ESPORT'
|
||||
|
||||
// export type EventDTO = {
|
||||
// id?: number;
|
||||
// owner: number; // nem kell
|
||||
// status?: EventStatus;
|
||||
// name: string;
|
||||
// description?: string;
|
||||
// image?: string;
|
||||
// location?: string;
|
||||
// startTime: string; //date!
|
||||
// endTime?: string; //date!
|
||||
// championshipLevel?: ChampionshipLevel;
|
||||
// parentChampionshipId?: number; // ez mi
|
||||
// category: EventCategory;
|
||||
// bio?: string; // ez mi
|
||||
// extras?: string; // ez mi
|
||||
// notice?: string; // ez mi
|
||||
// rosterName?: string;
|
||||
// rosterUrl?: string;
|
||||
// children?: EventEntity[]; // ez mi
|
||||
// };
|
||||
|
||||
@Schema()
|
||||
export class Event {
|
||||
@Prop({ required: true })
|
||||
name: string
|
||||
|
||||
@Prop({
|
||||
required: true,
|
||||
enum: ['ACTIVE', 'POSTPONED', 'CANCELLED', 'FINISHED'],
|
||||
})
|
||||
status: EventStatus
|
||||
|
||||
@Prop()
|
||||
description: string
|
||||
|
||||
@Prop()
|
||||
image: string
|
||||
|
||||
@Prop()
|
||||
location: string
|
||||
|
||||
@Prop()
|
||||
startTime: Date
|
||||
|
||||
@Prop()
|
||||
endTime: Date
|
||||
|
||||
@Prop()
|
||||
@Prop({
|
||||
required: true,
|
||||
enum: ['WORLD', 'CONTINENTAL', 'INTERNATIONAL', 'NATIONAL', 'AMATEUR'],
|
||||
})
|
||||
championshipLevel: ChampionshipLevel
|
||||
|
||||
@Prop({
|
||||
required: true,
|
||||
enum: ['CAR', 'BIKE', 'PLANE', 'BOAT', 'RC', 'ESPORT'],
|
||||
})
|
||||
category: string
|
||||
|
||||
@Prop()
|
||||
rosterName: string
|
||||
|
||||
@Prop()
|
||||
rosterUrl: string
|
||||
}
|
||||
|
||||
export const EventSchema = SchemaFactory.createForClass(Event)
|
67
src/schemas/user.schema.ts
Normal file
67
src/schemas/user.schema.ts
Normal file
@ -0,0 +1,67 @@
|
||||
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'
|
||||
import { HydratedDocument } from 'mongoose'
|
||||
|
||||
export type UserDocument = HydratedDocument<User>
|
||||
export type RegistrationStatus = 'PENDING' | 'CONFIRMED'
|
||||
|
||||
// export type Userr = {
|
||||
// id: number;
|
||||
// profileType: {
|
||||
// id: number;
|
||||
// name: string;
|
||||
// };
|
||||
// email: string;
|
||||
// country: {
|
||||
// id: number;
|
||||
// name: string;
|
||||
// languageKey: keyof typeof countries;
|
||||
// };
|
||||
// status: RegistrationStatus;
|
||||
// profilePic?: string;
|
||||
// description?: string;
|
||||
// contacts?: string;
|
||||
// birthDate: string;
|
||||
// firstName: string;
|
||||
// lastName: string;
|
||||
// racerName: string;
|
||||
// interests?: UserInterestDTO[];
|
||||
// socialLinks?: SocialLinkDTO[];
|
||||
// sponsors?: SponsorDTO[];
|
||||
// }
|
||||
|
||||
@Schema()
|
||||
export class User {
|
||||
@Prop({ required: true })
|
||||
profileType: string
|
||||
@Prop({ required: true })
|
||||
email: string
|
||||
@Prop({ required: true })
|
||||
password: string
|
||||
@Prop({ required: true })
|
||||
country: string
|
||||
@Prop({ required: true, enum: ['PENDING', 'CONFIRMED'] })
|
||||
status: RegistrationStatus
|
||||
@Prop()
|
||||
profilePic: string
|
||||
@Prop()
|
||||
description: string
|
||||
@Prop()
|
||||
contacts: string
|
||||
@Prop({ required: true })
|
||||
birthDate: Date
|
||||
@Prop({ required: true })
|
||||
firstName: string
|
||||
@Prop({ required: true })
|
||||
lastName: string
|
||||
@Prop({ required: true })
|
||||
racerName: string
|
||||
@Prop({ required: true })
|
||||
interests: string[]
|
||||
socialLinks: string[]
|
||||
@Prop({ required: true, type: {} })
|
||||
attributes: any
|
||||
@Prop()
|
||||
registrationToken: string
|
||||
}
|
||||
|
||||
export const UserSchema = SchemaFactory.createForClass(User)
|
25
src/search/dto/advanced-search-event.dto.ts
Normal file
25
src/search/dto/advanced-search-event.dto.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import { IsArray, IsString } from 'class-validator'
|
||||
|
||||
export class EventAdvancedSearchDto {
|
||||
// ownerId: number ???
|
||||
@IsArray()
|
||||
days: Array<string>
|
||||
|
||||
@IsString()
|
||||
name: string
|
||||
|
||||
@IsString()
|
||||
description: string
|
||||
|
||||
@IsArray()
|
||||
locations: string[]
|
||||
|
||||
@IsArray()
|
||||
levels: string[]
|
||||
// parentId: number ???
|
||||
// parentName: string ???
|
||||
// attendeeId: number ???
|
||||
|
||||
@IsString()
|
||||
category: string //EventCategory
|
||||
}
|
30
src/search/dto/advanced-search-profile.dto.ts
Normal file
30
src/search/dto/advanced-search-profile.dto.ts
Normal file
@ -0,0 +1,30 @@
|
||||
import { IsArray, IsObject, IsString } from 'class-validator'
|
||||
|
||||
export class ProfileAdvancedSearchDto {
|
||||
@IsString()
|
||||
email?: string
|
||||
|
||||
@IsString()
|
||||
profileGroup?: string
|
||||
|
||||
@IsString()
|
||||
profileType?: string
|
||||
|
||||
@IsString()
|
||||
name?: string
|
||||
|
||||
@IsArray()
|
||||
countries?: string[]
|
||||
|
||||
@IsString()
|
||||
fromDate?: string
|
||||
|
||||
@IsString()
|
||||
toDate?: string
|
||||
|
||||
@IsObject()
|
||||
attributes?: Record<string, any>
|
||||
|
||||
@IsArray()
|
||||
interests?: string[]
|
||||
}
|
8
src/search/dto/general-search.dto.ts
Normal file
8
src/search/dto/general-search.dto.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { IsNotEmpty, IsString } from 'class-validator'
|
||||
import { PaginationDto } from 'src/common/dto/pagination.dto'
|
||||
|
||||
export class GeneralSearchDto extends PaginationDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
term: string
|
||||
}
|
18
src/search/search.controller.spec.ts
Normal file
18
src/search/search.controller.spec.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { SearchController } from './search.controller';
|
||||
|
||||
describe('SearchController', () => {
|
||||
let controller: SearchController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [SearchController],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<SearchController>(SearchController);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
});
|
37
src/search/search.controller.ts
Normal file
37
src/search/search.controller.ts
Normal file
@ -0,0 +1,37 @@
|
||||
import { Body, Controller, Get, Query } from '@nestjs/common'
|
||||
import { SearchService } from './search.service'
|
||||
import { GeneralSearchDto } from './dto/general-search.dto'
|
||||
import { ProfileAdvancedSearchDto } from './dto/advanced-search-profile.dto'
|
||||
import { PaginationDto } from 'src/common/dto/pagination.dto'
|
||||
import { EventAdvancedSearchDto } from './dto/advanced-search-event.dto'
|
||||
|
||||
@Controller('search')
|
||||
export class SearchController {
|
||||
constructor(private readonly searchService: SearchService) {}
|
||||
|
||||
@Get('profile')
|
||||
advancedSearchProfile(
|
||||
@Query() pagination: PaginationDto,
|
||||
@Body() body: ProfileAdvancedSearchDto,
|
||||
) {
|
||||
return this.searchService.advancedSearchProfile(pagination, body)
|
||||
}
|
||||
|
||||
@Get('event')
|
||||
advancedSearchEvent(
|
||||
@Query() pagination: PaginationDto,
|
||||
@Body() body: EventAdvancedSearchDto,
|
||||
) {
|
||||
return this.searchService.advancedSearchEvent(pagination, body)
|
||||
}
|
||||
|
||||
@Get('general/profile')
|
||||
generalSearchProfile(@Query() queryParams: GeneralSearchDto) {
|
||||
return this.searchService.generalSearchProfile(queryParams)
|
||||
}
|
||||
|
||||
@Get('general/event')
|
||||
generalSearchEvent(@Query() queryParams: GeneralSearchDto) {
|
||||
return this.searchService.generalSearchEvent(queryParams)
|
||||
}
|
||||
}
|
15
src/search/search.module.ts
Normal file
15
src/search/search.module.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import { Module } from '@nestjs/common'
|
||||
import { SearchController } from './search.controller'
|
||||
import { SearchService } from './search.service'
|
||||
import { MongooseModule } from '@nestjs/mongoose'
|
||||
import { User, UserSchema } from 'src/schemas/user.schema'
|
||||
import { Event, EventSchema } from 'src/schemas/event.schema'
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
MongooseModule.forFeature([{ name: Event.name, schema: EventSchema }]),
|
||||
],
|
||||
controllers: [SearchController],
|
||||
providers: [SearchService],
|
||||
})
|
||||
export class SearchModule {}
|
18
src/search/search.service.spec.ts
Normal file
18
src/search/search.service.spec.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { SearchService } from './search.service';
|
||||
|
||||
describe('SearchService', () => {
|
||||
let service: SearchService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [SearchService],
|
||||
}).compile();
|
||||
|
||||
service = module.get<SearchService>(SearchService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
61
src/search/search.service.ts
Normal file
61
src/search/search.service.ts
Normal file
@ -0,0 +1,61 @@
|
||||
import { Injectable } from '@nestjs/common'
|
||||
import { InjectModel } from '@nestjs/mongoose'
|
||||
import { Model } from 'mongoose'
|
||||
import { User, UserDocument } from 'src/schemas/user.schema'
|
||||
import { GeneralSearchDto } from './dto/general-search.dto'
|
||||
import { ProfileAdvancedSearchDto } from './dto/advanced-search-profile.dto'
|
||||
import { PaginationDto } from 'src/common/dto/pagination.dto'
|
||||
import { Event, EventDocument } from 'src/schemas/event.schema'
|
||||
import { EventAdvancedSearchDto } from './dto/advanced-search-event.dto'
|
||||
|
||||
@Injectable()
|
||||
export class SearchService {
|
||||
constructor(
|
||||
// @InjectModel(User.name) private userModel: Model<User>, TODO DOESNT WORK
|
||||
// @InjectModel(Event.name) private eventModel: Model<Event>,
|
||||
) {}
|
||||
|
||||
async advancedSearchProfile(
|
||||
pagination: PaginationDto,
|
||||
body: ProfileAdvancedSearchDto,
|
||||
) {
|
||||
let profiles: UserDocument[]
|
||||
// const query = this.userModel.find(body)
|
||||
//
|
||||
// if (pagination.page && pagination.size) {
|
||||
// profiles = await query
|
||||
// .skip(pagination.size * pagination.page)
|
||||
// .limit(pagination.size)
|
||||
// }
|
||||
//
|
||||
// profiles = await query
|
||||
//
|
||||
return profiles
|
||||
}
|
||||
|
||||
async advancedSearchEvent(
|
||||
pagination: PaginationDto,
|
||||
body: EventAdvancedSearchDto,
|
||||
) {
|
||||
// let events: EventDocument[]
|
||||
// const query = this.eventModel.find(body)
|
||||
//
|
||||
// if (pagination.page && pagination.size) {
|
||||
// events = await query
|
||||
// .skip(pagination.size * pagination.page)
|
||||
// .limit(pagination.size)
|
||||
// }
|
||||
//
|
||||
// events = await query
|
||||
//
|
||||
// return events
|
||||
}
|
||||
|
||||
async generalSearchProfile(queryParams: GeneralSearchDto) {
|
||||
// todo
|
||||
}
|
||||
|
||||
async generalSearchEvent(queryParams: GeneralSearchDto) {
|
||||
// todo
|
||||
}
|
||||
}
|
7
src/users/dto/create-user.dto.ts
Normal file
7
src/users/dto/create-user.dto.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import { IsNotEmpty, IsString } from 'class-validator'
|
||||
|
||||
export class CreateUserDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
username: string
|
||||
}
|
31
src/users/dto/update-user.dto.ts
Normal file
31
src/users/dto/update-user.dto.ts
Normal file
@ -0,0 +1,31 @@
|
||||
import { IsNotEmpty, IsString } from 'class-validator'
|
||||
|
||||
export class UpdateUserDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
email: string
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
racerName: string
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
firstName: string
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
lastName: string
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
country: string
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
profileType: string
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
birthDate: string
|
||||
}
|
20
src/users/users.controller.spec.ts
Normal file
20
src/users/users.controller.spec.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing'
|
||||
import { UsersController } from './users.controller'
|
||||
import { UsersService } from './users.service'
|
||||
|
||||
describe('UsersController', () => {
|
||||
let controller: UsersController
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [UsersController],
|
||||
providers: [UsersService],
|
||||
}).compile()
|
||||
|
||||
controller = module.get<UsersController>(UsersController)
|
||||
})
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined()
|
||||
})
|
||||
})
|
43
src/users/users.controller.ts
Normal file
43
src/users/users.controller.ts
Normal file
@ -0,0 +1,43 @@
|
||||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Body,
|
||||
Param,
|
||||
Delete,
|
||||
UseGuards,
|
||||
Put,
|
||||
} from '@nestjs/common'
|
||||
import { UsersService } from './users.service'
|
||||
import { UpdateUserDto } from './dto/update-user.dto'
|
||||
import { AuthGuard } from 'src/auth/auth.guard'
|
||||
|
||||
@UseGuards(AuthGuard)
|
||||
@Controller('users')
|
||||
export class UsersController {
|
||||
constructor(private readonly usersService: UsersService) {}
|
||||
|
||||
@Get('check/:email')
|
||||
check(@Param('email') email: string) {
|
||||
return this.usersService.checkEmailExists(email);
|
||||
}
|
||||
|
||||
// @Get()
|
||||
// findAll() {
|
||||
// return this.usersService.findAll()
|
||||
// }
|
||||
//
|
||||
// @Get(':id')
|
||||
// findOne(@Param('id') id: string) {
|
||||
// return this.usersService.findOne(id)
|
||||
// }
|
||||
//
|
||||
@Put(':id')
|
||||
update(@Param('id') id: string, @Body() updateUserDto: UpdateUserDto) {
|
||||
return this.usersService.update(id, updateUserDto)
|
||||
}
|
||||
//
|
||||
// @Delete(':id')
|
||||
// remove(@Param('id') id: string) {
|
||||
// return this.usersService.remove(id)
|
||||
// }
|
||||
}
|
16
src/users/users.module.ts
Normal file
16
src/users/users.module.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import { Module } from '@nestjs/common'
|
||||
import { UsersService } from './users.service'
|
||||
import { UsersController } from './users.controller'
|
||||
import { MongooseModule } from '@nestjs/mongoose'
|
||||
import { User, UserSchema } from 'src/schemas/user.schema'
|
||||
import { ConfigModule } from '@nestjs/config'
|
||||
|
||||
@Module({
|
||||
controllers: [UsersController],
|
||||
providers: [UsersService],
|
||||
imports: [
|
||||
ConfigModule,
|
||||
MongooseModule.forFeature([{ name: User.name, schema: UserSchema }]),
|
||||
],
|
||||
})
|
||||
export class UsersModule {}
|
18
src/users/users.service.spec.ts
Normal file
18
src/users/users.service.spec.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing'
|
||||
import { UsersService } from './users.service'
|
||||
|
||||
describe('UsersService', () => {
|
||||
let service: UsersService
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [UsersService],
|
||||
}).compile()
|
||||
|
||||
service = module.get<UsersService>(UsersService)
|
||||
})
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined()
|
||||
})
|
||||
})
|
34
src/users/users.service.ts
Normal file
34
src/users/users.service.ts
Normal file
@ -0,0 +1,34 @@
|
||||
import { Injectable } from '@nestjs/common'
|
||||
import { UpdateUserDto } from './dto/update-user.dto'
|
||||
import { InjectModel } from '@nestjs/mongoose'
|
||||
import { User } from 'src/schemas/user.schema'
|
||||
import { Model } from 'mongoose'
|
||||
|
||||
@Injectable()
|
||||
export class UsersService {
|
||||
constructor(@InjectModel(User.name) private userModel: Model<User>) {}
|
||||
|
||||
async checkEmailExists(email: string) {
|
||||
const user = await this.userModel.findOne({ email })
|
||||
|
||||
if (user) return true
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
async findAll() {
|
||||
return await this.userModel.find({})
|
||||
}
|
||||
|
||||
async findOne(_id: string) {
|
||||
return await this.userModel.findById({ _id })
|
||||
}
|
||||
|
||||
async update(_id: string, updateUserDto: UpdateUserDto) {
|
||||
return await this.userModel.findOneAndUpdate({ _id }, updateUserDto)
|
||||
}
|
||||
|
||||
async remove(_id: string) {
|
||||
return await this.userModel.deleteOne({ _id })
|
||||
}
|
||||
}
|
24
test/app.e2e-spec.ts
Normal file
24
test/app.e2e-spec.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { INestApplication } from '@nestjs/common';
|
||||
import * as request from 'supertest';
|
||||
import { AppModule } from './../src/app.module';
|
||||
|
||||
describe('AppController (e2e)', () => {
|
||||
let app: INestApplication;
|
||||
|
||||
beforeEach(async () => {
|
||||
const moduleFixture: TestingModule = await Test.createTestingModule({
|
||||
imports: [AppModule],
|
||||
}).compile();
|
||||
|
||||
app = moduleFixture.createNestApplication();
|
||||
await app.init();
|
||||
});
|
||||
|
||||
it('/ (GET)', () => {
|
||||
return request(app.getHttpServer())
|
||||
.get('/')
|
||||
.expect(200)
|
||||
.expect('Hello World!');
|
||||
});
|
||||
});
|
9
test/jest-e2e.json
Normal file
9
test/jest-e2e.json
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"moduleFileExtensions": ["js", "json", "ts"],
|
||||
"rootDir": ".",
|
||||
"testEnvironment": "node",
|
||||
"testRegex": ".e2e-spec.ts$",
|
||||
"transform": {
|
||||
"^.+\\.(t|j)s$": "ts-jest"
|
||||
}
|
||||
}
|
4
tsconfig.build.json
Normal file
4
tsconfig.build.json
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"exclude": ["node_modules", "test", "dist", "**/*spec.ts"]
|
||||
}
|
21
tsconfig.json
Normal file
21
tsconfig.json
Normal file
@ -0,0 +1,21 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"declaration": true,
|
||||
"removeComments": true,
|
||||
"emitDecoratorMetadata": true,
|
||||
"experimentalDecorators": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"target": "ES2021",
|
||||
"sourceMap": true,
|
||||
"outDir": "./dist",
|
||||
"baseUrl": "./",
|
||||
"incremental": true,
|
||||
"skipLibCheck": true,
|
||||
"strictNullChecks": false,
|
||||
"noImplicitAny": false,
|
||||
"strictBindCallApply": false,
|
||||
"forceConsistentCasingInFileNames": false,
|
||||
"noFallthroughCasesInSwitch": false
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user