Skip to content

Commit

Permalink
Merge pull request #33 from Shpendiiiii/main
Browse files Browse the repository at this point in the history
Fixed #20
  • Loading branch information
Mohmn authored Jul 29, 2024
2 parents 7418088 + 3e9ec2f commit d5c478b
Show file tree
Hide file tree
Showing 25 changed files with 329 additions and 197 deletions.
26 changes: 26 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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',
'prettier/prettier': 0,
},
};
42 changes: 0 additions & 42 deletions .eslintrc.json

This file was deleted.

3 changes: 0 additions & 3 deletions apps/like/prisma/prisma.ts

This file was deleted.

31 changes: 0 additions & 31 deletions apps/like/prisma/schema.prisma

This file was deleted.

35 changes: 0 additions & 35 deletions apps/like/prisma/seed.ts

This file was deleted.

20 changes: 14 additions & 6 deletions apps/like/src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
import { Module } from '@nestjs/common';
import { UserModule } from './user/user.module';
import { ObjectModule } from './object/object.module';
import { TypeModule } from './type/type.module';
import { PrismaModule } from './prisma/prisma.module';
import { UserService } from './user/user.service';
import { TypeService } from './type/type.service';
import { UserController } from './user/user.controller';
import { TypeController } from './type/type.controller';
import { ConfigModule } from '@nestjs/config';
import { ObjectModule } from './object/object.module';
import { ObjectController } from './object/object.controller';
import { ObjectService } from './object/object.service';

@Module({
imports: [
ObjectModule,
ConfigModule.forRoot({ isGlobal: true }),
TypeModule,
UserModule,
PrismaModule
ObjectModule,
PrismaModule,
],
controllers: [],
providers: [],
controllers: [UserController, TypeController, ObjectController],
providers: [UserService, TypeService, ObjectService],
})
export class AppModule {}
export class AppModule {}
8 changes: 5 additions & 3 deletions apps/like/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { Logger } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { setupSwagger } from '../../../libs/utils/swagger';

async function bootstrap() {
const app = await NestFactory.create(AppModule);
const port = process.env.PORT || 3006;
if (process.env.NODE_ENV !== 'production') {
setupSwagger(app);
}
await app.listen(port);
Logger.log(
`🚀 Application is running on: http://localhost:${port}`
);
Logger.log(`🚀 Application is running on: http://localhost:${port}`);
}

bootstrap();
13 changes: 12 additions & 1 deletion apps/like/src/object/object.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
import { Body, Controller, Get, Post, Put, ValidationPipe, HttpStatus, Param, Req, Res } from '@nestjs/common';
import {
Body,

Check warning on line 2 in apps/like/src/object/object.controller.ts

View workflow job for this annotation

GitHub Actions / Run all tests

'Body' is defined but never used
Controller,
Get,
Post,
Put,

Check warning on line 6 in apps/like/src/object/object.controller.ts

View workflow job for this annotation

GitHub Actions / Run all tests

'Put' is defined but never used
ValidationPipe,

Check warning on line 7 in apps/like/src/object/object.controller.ts

View workflow job for this annotation

GitHub Actions / Run all tests

'ValidationPipe' is defined but never used
HttpStatus,

Check warning on line 8 in apps/like/src/object/object.controller.ts

View workflow job for this annotation

GitHub Actions / Run all tests

'HttpStatus' is defined but never used
Param,

Check warning on line 9 in apps/like/src/object/object.controller.ts

View workflow job for this annotation

GitHub Actions / Run all tests

'Param' is defined but never used
Req,

Check warning on line 10 in apps/like/src/object/object.controller.ts

View workflow job for this annotation

GitHub Actions / Run all tests

'Req' is defined but never used
Res,

Check warning on line 11 in apps/like/src/object/object.controller.ts

View workflow job for this annotation

GitHub Actions / Run all tests

'Res' is defined but never used
} from '@nestjs/common';
import { ObjectService } from './object.service';

Check warning on line 13 in apps/like/src/object/object.controller.ts

View workflow job for this annotation

GitHub Actions / Run all tests

'ObjectService' is defined but never used
import jwt from 'jsonwebtoken';

Check warning on line 14 in apps/like/src/object/object.controller.ts

View workflow job for this annotation

GitHub Actions / Run all tests

'jwt' is defined but never used

Expand Down
4 changes: 1 addition & 3 deletions apps/like/src/object/object.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { Injectable } from '@nestjs/common';

@Injectable()
export class ObjectService {

}
export class ObjectService {}
13 changes: 12 additions & 1 deletion apps/like/src/prisma/prisma.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { PrismaClient } from '@prisma/client';

@Injectable()
export class PrismaService extends PrismaClient{}
export class PrismaService extends PrismaClient {
constructor(config: ConfigService) {
super({
datasources: {
db: {
url: config.get('DATABASE_URL'),
},
},
});
}
}
58 changes: 35 additions & 23 deletions apps/like/src/type/type.controller.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,45 @@
import { Body, Controller, Get, Post, Put, ValidationPipe, HttpStatus, Param, Req, Res, Patch } from '@nestjs/common';
import {
Body,
Controller,
Get,
Post,
Put,

Check warning on line 6 in apps/like/src/type/type.controller.ts

View workflow job for this annotation

GitHub Actions / Run all tests

'Put' is defined but never used
ValidationPipe,
HttpStatus,
Param,
Req,
Res,
Patch,
} from '@nestjs/common';
import { CreatePostDto, EditPostDto, UserLikePostDto } from 'libs/validation';
import { TypeService} from './type.service';
import { TypeService } from './type.service';
import jwt from 'jsonwebtoken';

@Controller('types')
export class TypeController {
constructor( ) {}
constructor() {}

Check failure on line 20 in apps/like/src/type/type.controller.ts

View workflow job for this annotation

GitHub Actions / Run all tests

Unexpected empty constructor

// @Get()
// async handleGetAllTypes(@Req() req, @Res() res) {
// consider put the following inside a middleware or an authGuard
// const authHeader = req.get('authorization');
// if (!authHeader) {
// return res.status(401).send('Authorization header is missing');
// }
// const token = authHeader.split(' ')[1];
// try {
// const decodedToken = await jwt.decode(token);
// const roles = decodedToken['realm_access']['roles'];
// for (let i = 0; i < roles.length; i++) {
// if (roles[i] === 'default-roles-testing-realm') {
// return res.status(200).send('handleGetAllTypes');
// }
// }
// return res.status(403).send('Forbidden');
// }
// catch(error) {
// return res.status(401).send('Authorization failed');
// }
// consider put the following inside a middleware or an authGuard
// const authHeader = req.get('authorization');
// if (!authHeader) {
// return res.status(401).send('Authorization header is missing');
// }
// const token = authHeader.split(' ')[1];
// try {
// const decodedToken = await jwt.decode(token);
// const roles = decodedToken['realm_access']['roles'];
// for (let i = 0; i < roles.length; i++) {
// if (roles[i] === 'default-roles-testing-realm') {
// return res.status(200).send('handleGetAllTypes');
// }
// }
// return res.status(403).send('Forbidden');
// }
// catch(error) {
// return res.status(401).send('Authorization failed');
// }
// return res.status(200).send('handleGetAllTypes');
// }

Expand All @@ -45,4 +57,4 @@ export class TypeController {
async handleEditType() {
return 'handleEditType';
}
}
}
6 changes: 1 addition & 5 deletions apps/like/src/type/type.service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import { Injectable } from '@nestjs/common';

@Injectable()
export class TypeService {



}
export class TypeService {}
32 changes: 27 additions & 5 deletions apps/like/src/user/user.controller.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,34 @@
import { Body, Controller, Post, Get, Param, ParseIntPipe, ValidationPipe } from '@nestjs/common';
import {
Body,
Controller,
Post,
Get,
Param,
ParseIntPipe,
ValidationPipe
} from '@nestjs/common';
import { UserService } from './user.service';
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';

@Controller('users')
@Controller('user')
@ApiTags('user')
export class UserController {
constructor( ) {}
constructor(private userService: UserService) {
}

@Get(':user_uuid/types/:type_uuid')
async handleGetUserLikes(@Param('user_uuid') user_uuid: string) {
return 'handleGetUserLikes';
@ApiOperation({ summary: 'Get user likes on type by user id'})
@ApiResponse({
status: 200,
description: 'Successfully retrieved user activities',
})
@ApiResponse({
status: 404,
description: 'Not Found',
})
async handleGetUserLikes(@Param('user_uuid') user_uuid: string, @Param('type_uuid') type_uuid: string) {
return this.userService.getUserLikesOnType(user_uuid, type_uuid);
}


}
5 changes: 3 additions & 2 deletions apps/like/src/user/user.module.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Module } from '@nestjs/common';
import { UserController } from './user.controller';
import { UserService } from './user.service';
import { PrismaService } from '../prisma/prisma.service';

@Module({
imports: [],
controllers: [UserController],
providers: [UserService],
providers: [UserService, PrismaService],
exports: [UserService],
})
export class UserModule {}
Loading

0 comments on commit d5c478b

Please sign in to comment.