tous les trucs du user sont ok, maintenant refonte des requêtes d'amitiés. C'est bien avancé, reste àa tester deux trois trucs

This commit is contained in:
batche
2022-11-04 18:34:02 +01:00
parent 08d02e709b
commit 7fd8147140
39 changed files with 328 additions and 291 deletions

View File

@@ -50,8 +50,8 @@ services:
postgresql: postgresql:
container_name: nestjs_postgresql container_name: nestjs_postgresql
image: postgres image: postgres
expose: ports:
- "5432" - 5432:5432
networks: networks:
- transcendance_network - transcendance_network
volumes: volumes:

View File

@@ -18,7 +18,7 @@ let AuthenticationService = class AuthenticationService {
} }
async validateUser(createUsersDto) { async validateUser(createUsersDto) {
console.log("Validate inside authentication.service.ts"); console.log("Validate inside authentication.service.ts");
const user = await this.userService.findOneByFourtyTwoId(createUsersDto.fourtyTwoId); const user = await this.userService.findOneByFourtyTwoId(createUsersDto.fortyTwoId);
if (user) if (user)
return user; return user;
return this.userService.create(createUsersDto); return this.userService.create(createUsersDto);

View File

@@ -1 +1 @@
{"version":3,"file":"authentication.service.js","sourceRoot":"","sources":["../../../src/auth/42/authentication.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAG5C,6DAAuD;AAIhD,IAAM,qBAAqB,GAA3B,MAAM,qBAAqB;IACjC,YACmB,WAAyB;QAAzB,gBAAW,GAAX,WAAW,CAAc;IAExC,CAAC;IAEL,KAAK,CAAC,YAAY,CAAC,cAA8B;QAChD,OAAO,CAAC,GAAG,CAAC,2CAA2C,CAAC,CAAC;QACzD,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,oBAAoB,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC;QACrF,IAAI,IAAI;YACP,OAAO,IAAI,CAAC;QACb,OAAO,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;IAChD,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,YAAqB;QACnC,OAAO,MAAM,IAAI,CAAC,WAAW,CAAC,oBAAoB,CAAC,YAAY,CAAC,CAAC;IAClE,CAAC;CAMD,CAAA;AAtBY,qBAAqB;IADjC,IAAA,mBAAU,GAAE;qCAGoB,4BAAY;GAFhC,qBAAqB,CAsBjC;AAtBY,sDAAqB"} {"version":3,"file":"authentication.service.js","sourceRoot":"","sources":["../../../src/auth/42/authentication.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAG5C,6DAAuD;AAIhD,IAAM,qBAAqB,GAA3B,MAAM,qBAAqB;IACjC,YACmB,WAAyB;QAAzB,gBAAW,GAAX,WAAW,CAAc;IAExC,CAAC;IAEL,KAAK,CAAC,YAAY,CAAC,cAA8B;QAChD,OAAO,CAAC,GAAG,CAAC,2CAA2C,CAAC,CAAC;QACzD,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,oBAAoB,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC;QACpF,IAAI,IAAI;YACP,OAAO,IAAI,CAAC;QACb,OAAO,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;IAChD,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,YAAqB;QACnC,OAAO,MAAM,IAAI,CAAC,WAAW,CAAC,oBAAoB,CAAC,YAAY,CAAC,CAAC;IAClE,CAAC;CAMD,CAAA;AAtBY,qBAAqB;IADjC,IAAA,mBAAU,GAAE;qCAGoB,4BAAY;GAFhC,qBAAqB,CAsBjC;AAtBY,sDAAqB"}

View File

@@ -27,7 +27,7 @@ let FortyTwoStrategy = class FortyTwoStrategy extends (0, passport_1.PassportStr
async validate(accessToken, refreshToken, profile, callbackURL) { async validate(accessToken, refreshToken, profile, callbackURL) {
console.log("Validate inside strategy.ts"); console.log("Validate inside strategy.ts");
console.log(profile.id, profile.username, profile.phoneNumbers[0].value, profile.emails[0].value, profile.photos[0].value); console.log(profile.id, profile.username, profile.phoneNumbers[0].value, profile.emails[0].value, profile.photos[0].value);
const userDTO = { fourtyTwoId: profile.id, username: profile.username, email: profile.emails[0].value, image_url: profile.photos[0].value }; const userDTO = { fortyTwoId: profile.id, username: profile.username, email: profile.emails[0].value, image_url: profile.photos[0].value };
const user = await this.authenticationService.validateUser(userDTO); const user = await this.authenticationService.validateUser(userDTO);
if (!user) if (!user)
throw new common_1.UnauthorizedException(); throw new common_1.UnauthorizedException();

View File

@@ -1 +1 @@
{"version":3,"file":"42strategy.js","sourceRoot":"","sources":["../../../../src/auth/42/strategy/42strategy.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yCAAoD;AACpD,+CAAoD;AACpD,2CAAmE;AACnE,sEAAkE;AAI3D,IAAM,gBAAgB,GAAtB,MAAM,gBAAiB,SAAQ,IAAA,2BAAgB,EAAC,cAAQ,EAAE,IAAI,CAAC;IACrE,YAAoB,qBAA4C;QAChE,KAAK,CAAC;YACJ,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,kBAAkB;YACxC,YAAY,EAAE,OAAO,CAAC,GAAG,CAAC,sBAAsB;YAChD,WAAW,EAAE,OAAO,CAAC,GAAG,CAAC,qBAAqB;YAC9C,KAAK,EAAE,CAAC,QAAQ,CAAC;SAClB,CAAC,CAAC;QANiB,0BAAqB,GAArB,qBAAqB,CAAuB;IAO/D,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,WAAmB,EAAE,YAAoB,EAAE,OAAgB,EAAE,WAAmB;QAChG,OAAO,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAC;QAC3C,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,EAAE,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QAC3H,MAAM,OAAO,GAAoB,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,K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AAE,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QAC3H,MAAM,OAAO,GAAoB,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC;QAC5J,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,qBAAqB,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;QACpE,IAAI,CAAC,IAAI;YACR,MAAM,IAAI,8BAAqB,EAAE,CAAC;QACnC,OAAO,IAAI,CAAC;IACX,CAAC;CACF,CAAA;AAnBY,gBAAgB;IAD5B,IAAA,mBAAU,GAAE;qCAE+B,8CAAqB;GADpD,gBAAgB,CAmB5B;AAnBY,4CAAgB"}

View File

@@ -22,7 +22,7 @@ let SessionSerializer = class SessionSerializer extends passport_1.PassportSeria
done(null, user); done(null, user);
} }
async deserializeUser(user, done) { async deserializeUser(user, done) {
const userDB = await this.authservice.findUser(user.fourtyTwoId); const userDB = await this.authservice.findUser(user.fortyTwoId);
if (userDB) if (userDB)
done(null, userDB); done(null, userDB);
else else

View File

@@ -1 +1 @@
{"version":3,"file":"serializer.js","sourceRoot":"","sources":["../../../../src/auth/42/utils/serializer.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+CAAsD;AACtD,2CAA4C;AAE5C,sEAAkE;AAG3D,IAAM,iBAAiB,GAAvB,MAAM,iBAAkB,SAAQ,6BAAkB;IACxD,YAA6B,WAAmC;QAC/D,KAAK,EAAE,CAAC;QADoB,gBAAW,GAAX,WAAW,CAAwB;IAEhE,CAAC;IAED,aAAa,CAAC,IAAW,EAAE,IAAyC;QACnE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAClB,CAAC;IAED,KAAK,CAAC,eAAe,CAAC,IAAW,EAAE,IAAyC;QAC3E,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QACjE,IAAI,MAAM;YACT,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;;YAEnB,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACnB,CAAC;CACD,CAAA;AAhBY,iBAAiB;IAD7B,IAAA,mBAAU,GAAE;qCAE+B,8CAAqB;GADpD,iBAAiB,CAgB7B;AAhBY,8CAAiB"} {"version":3,"file":"serializer.js","sourceRoot":"","sources":["../../../../src/auth/42/utils/serializer.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+CAAsD;AACtD,2CAA4C;AAE5C,sEAAkE;AAG3D,IAAM,iBAAiB,GAAvB,MAAM,iBAAkB,SAAQ,6BAAkB;IACxD,YAA6B,WAAmC;QAC/D,KAAK,EAAE,CAAC;QADoB,gBAAW,GAAX,WAAW,CAAwB;IAEhE,CAAC;IAED,aAAa,CAAC,IAAW,EAAE,IAAyC;QACnE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAClB,CAAC;IAED,KAAK,CAAC,eAAe,CAAC,IAAW,EAAE,IAAyC;QAC3E,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAChE,IAAI,MAAM;YACT,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;;YAEnB,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACnB,CAAC;CACD,CAAA;AAhBY,iBAAiB;IAD7B,IAAA,mBAAU,GAAE;qCAE+B,8CAAqB;GADpD,iBAAiB,CAgB7B;AAhBY,8CAAiB"}

View File

@@ -1 +1 @@
{"version":3,"file":"friendship.entity.js","sourceRoot":"","sources":["../../../src/friendship/entities/friendship.entity.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,qCAAmI;AACnI,kEAAwD;AAExD,IAAY,gBAKX;AALD,WAAY,gBAAgB;IAC3B,mCAAe,CAAA;IACf,kCAAc,CAAA;IACd,kCAAc,CAAA;IACd,iCAAa,CAAA;AACd,CAAC,EALW,gBAAgB,GAAhB,wBAAgB,KAAhB,wBAAgB,QAK3B;AAGM,IAAM,UAAU,GAAhB,MAAM,UAAU;CAkBtB,CAAA;AAjBA;IAAC,IAAA,gCAAsB,GAAE;;sCACd;AAEX;IAAC,IAAA,0BAAgB,GAAE;8BACZ,IAAI;wCAAC;AAGZ;IAAC,IAAA,gBAAM,GAAE;IACR,IAAA,mBAAS,EAAC,IAAI,CAAC,EAAE,CAAC,kBAAI,EAAE,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC;;+CAC9B;AAEpB;IAAC,IAAA,gBAAM,GAAE;IACR,IAAA,mBAAS,EAAC,IAAI,CAAC,EAAE,CAAC,kBAAI,EAAE,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC;;+CAC9B;AAEpB;IAAC,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,gBAAgB,EAAE,OAAO,EAAE,gBAAgB,CAAC,SAAS,EAAC,CAAC;;0CAC5D;AAjBb,UAAU;IADtB,IAAA,gBAAM,EAAC,aAAa,CAAC;GACT,UAAU,CAkBtB;AAlBY,gCAAU"} {"version":3,"file":"friendship.entity.js","sourceRoot":"","sources":["../../../src/friendship/entities/friendship.entity.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,qCAAmI;AACnI,kEAAwD;AAExD,IAAY,gBAKX;AALD,WAAY,gBAAgB;IAC3B,mCAAe,CAAA;IACf,kCAAc,CAAA;IACd,kCAAc,CAAA;IACd,iCAAa,CAAA;AACd,CAAC,EALW,gBAAgB,GAAhB,wBAAgB,KAAhB,wBAAgB,QAK3B;AAGM,IAAM,UAAU,GAAhB,MAAM,UAAU;CAiBtB,CAAA;AAhBA;IAAC,IAAA,gCAAsB,GAAE;;sCACd;AAEX;IAAC,IAAA,0BAAgB,GAAE;8BACZ,IAAI;wCAAC;AAEZ;IAAC,IAAA,gBAAM,GAAE;IACR,IAAA,mBAAS,EAAC,IAAI,CAAC,EAAE,CAAC,kBAAI,EAAE,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC;;+CAC9B;AAEpB;IAAC,IAAA,gBAAM,GAAE;IACR,IAAA,mBAAS,EAAC,IAAI,CAAC,EAAE,CAAC,kBAAI,EAAE,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC;;+CAC9B;AAEpB;IAAC,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,gBAAgB,EAAE,OAAO,EAAE,gBAAgB,CAAC,SAAS,EAAC,CAAC;;0CAC5D;AAhBb,UAAU;IADtB,IAAA,gBAAM,EAAC,aAAa,CAAC;GACT,UAAU,CAiBtB;AAjBY,gCAAU"}

View File

@@ -1,15 +1,15 @@
import { HttpException } from '@nestjs/common';
import { CreateFriendshipDto } from './dto/create-friendship.dto'; import { CreateFriendshipDto } from './dto/create-friendship.dto';
import { UpdateFriendshipDto } from './dto/update-friendship.dto';
import { FriendshipService } from './friendship.service'; import { FriendshipService } from './friendship.service';
export declare class FriendshipController { export declare class FriendshipController {
private readonly friendshipService; private readonly friendshipService;
constructor(friendshipService: FriendshipService); constructor(friendshipService: FriendshipService);
findEmpty(userId: string): Promise<import("./entities/friendship.entity").Friendship[]>; findEmpty(req: any): Promise<import("./entities/friendship.entity").Friendship[]>;
findAllBlocked(userId: string): Promise<import("./entities/friendship.entity").Friendship[]>; findOneFriend(relationshipId: string, req: any): Promise<import("./entities/friendship.entity").Friendship[]>;
findAllPendantFriendshipRequested(userId: string): Promise<import("./entities/friendship.entity").Friendship[]>; create(createFriendshipDto: CreateFriendshipDto, req: any): HttpException | Promise<import("./entities/friendship.entity").Friendship>;
findAllPendantFriendshipReceived(userId: string): Promise<import("./entities/friendship.entity").Friendship[]>; update(relationshipId: string, status: string, req: any): Promise<import("./entities/friendship.entity").Friendship>;
findOneFriend(friendId: string): Promise<import("./entities/friendship.entity").Friendship[]>; remove(relationshipId: string): Promise<import("./entities/friendship.entity").Friendship>;
create(createFriendshipDto: CreateFriendshipDto): Promise<import("./entities/friendship.entity").Friendship>; findAllBlocked(req: any): Promise<import("./entities/friendship.entity").Friendship[]>;
update(relationshipId: string, { status }: UpdateFriendshipDto): Promise<import("./entities/friendship.entity").Friendship>; findAllPendantFriendshipRequested(req: any): Promise<import("./entities/friendship.entity").Friendship[]>;
remove(friendId: string): Promise<import("./entities/friendship.entity").Friendship[]>; findAllPendantFriendshipReceived(req: any): Promise<import("./entities/friendship.entity").Friendship[]>;
} }

View File

@@ -14,105 +14,117 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.FriendshipController = void 0; exports.FriendshipController = void 0;
const common_1 = require("@nestjs/common"); const common_1 = require("@nestjs/common");
const jwtGuards_1 = require("../auth/42/guards/jwtGuards"); const _42guards_1 = require("../auth/42/guards/42guards");
const create_friendship_dto_1 = require("./dto/create-friendship.dto"); const create_friendship_dto_1 = require("./dto/create-friendship.dto");
const update_friendship_dto_1 = require("./dto/update-friendship.dto");
const friendship_service_1 = require("./friendship.service"); const friendship_service_1 = require("./friendship.service");
let FriendshipController = class FriendshipController { let FriendshipController = class FriendshipController {
constructor(friendshipService) { constructor(friendshipService) {
this.friendshipService = friendshipService; this.friendshipService = friendshipService;
} }
findEmpty(userId) { findEmpty(req) {
return this.friendshipService.findAllFriends(userId); const user = req.user;
return this.friendshipService.findAllFriends(user.id);
} }
findAllBlocked(userId) { findOneFriend(relationshipId, req) {
return this.friendshipService.findAllBlockedFriends(userId); const user = req.user;
return this.friendshipService.findOneFriend(relationshipId, user.id);
} }
findAllPendantFriendshipRequested(userId) { create(createFriendshipDto, req) {
return this.friendshipService.findAllPendantRequestsForFriendship(userId); const user = req.user;
console.log(`User id: ${user.id}\n Friend id: ${createFriendshipDto.requesterId}`);
if (user.id === +createFriendshipDto.requesterId)
return this.friendshipService.create(createFriendshipDto, user);
return new common_1.HttpException('You can\'t request a frienship for another user', common_1.HttpStatus.FORBIDDEN);
} }
findAllPendantFriendshipReceived(userId) { update(relationshipId, status, req) {
return this.friendshipService.findAllReceivedRequestsForFriendship(userId); const user = req.user;
return this.friendshipService.updateFriendship(relationshipId, user, status);
} }
findOneFriend(friendId) { remove(relationshipId) {
return this.friendshipService.findOneFriend(friendId); return this.friendshipService.removeFriendship(relationshipId);
} }
create(createFriendshipDto) { findAllBlocked(req) {
return this.friendshipService.create(createFriendshipDto); const user = req.user;
return this.friendshipService.findAllBlockedFriends(user.id);
} }
update(relationshipId, { status }) { findAllPendantFriendshipRequested(req) {
return this.friendshipService.updateFriendship(relationshipId, { status }); const user = req.user;
return this.friendshipService.findAllPendantRequestsForFriendship(user.id);
} }
remove(friendId) { findAllPendantFriendshipReceived(req) {
return this.friendshipService.removeFriendship(friendId); const user = req.user;
return this.friendshipService.findAllReceivedRequestsForFriendship(user.id);
} }
}; };
__decorate([ __decorate([
(0, common_1.Get)(':userId/friends'), (0, common_1.Get)('myfriends'),
(0, common_1.UseGuards)(jwtGuards_1.JwtAuthGuard), (0, common_1.UseGuards)(_42guards_1.AuthenticateGuard),
__param(0, (0, common_1.Param)('userId')), __param(0, (0, common_1.Req)()),
__metadata("design:type", Function), __metadata("design:type", Function),
__metadata("design:paramtypes", [String]), __metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0) __metadata("design:returntype", void 0)
], FriendshipController.prototype, "findEmpty", null); ], FriendshipController.prototype, "findEmpty", null);
__decorate([ __decorate([
(0, common_1.Get)(':userId/blocked'), (0, common_1.Get)('myfriends/:relationshipId'),
(0, common_1.UseGuards)(jwtGuards_1.JwtAuthGuard), (0, common_1.UseGuards)(_42guards_1.AuthenticateGuard),
__param(0, (0, common_1.Param)('userId')), __param(0, (0, common_1.Param)('relationshipId')),
__param(1, (0, common_1.Req)()),
__metadata("design:type", Function), __metadata("design:type", Function),
__metadata("design:paramtypes", [String]), __metadata("design:paramtypes", [String, Object]),
__metadata("design:returntype", void 0)
], FriendshipController.prototype, "findAllBlocked", null);
__decorate([
(0, common_1.Get)(':userId/pending'),
(0, common_1.UseGuards)(jwtGuards_1.JwtAuthGuard),
__param(0, (0, common_1.Param)('userId')),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String]),
__metadata("design:returntype", void 0)
], FriendshipController.prototype, "findAllPendantFriendshipRequested", null);
__decorate([
(0, common_1.Get)(':userId/received'),
(0, common_1.UseGuards)(jwtGuards_1.JwtAuthGuard),
__param(0, (0, common_1.Param)('userId')),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String]),
__metadata("design:returntype", void 0)
], FriendshipController.prototype, "findAllPendantFriendshipReceived", null);
__decorate([
(0, common_1.Get)(':userId/myfriends/:friendId'),
(0, common_1.UseGuards)(jwtGuards_1.JwtAuthGuard),
__param(0, (0, common_1.Param)('friendId')),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String]),
__metadata("design:returntype", void 0) __metadata("design:returntype", void 0)
], FriendshipController.prototype, "findOneFriend", null); ], FriendshipController.prototype, "findOneFriend", null);
__decorate([ __decorate([
(0, common_1.Post)(), (0, common_1.Post)('myfriends'),
(0, common_1.HttpCode)(common_1.HttpStatus.CREATED), (0, common_1.HttpCode)(common_1.HttpStatus.CREATED),
(0, common_1.UseGuards)(jwtGuards_1.JwtAuthGuard), (0, common_1.UseGuards)(_42guards_1.AuthenticateGuard),
__param(0, (0, common_1.Body)()), __param(0, (0, common_1.Body)()),
__param(1, (0, common_1.Req)()),
__metadata("design:type", Function), __metadata("design:type", Function),
__metadata("design:paramtypes", [create_friendship_dto_1.CreateFriendshipDto]), __metadata("design:paramtypes", [create_friendship_dto_1.CreateFriendshipDto, Object]),
__metadata("design:returntype", void 0) __metadata("design:returntype", void 0)
], FriendshipController.prototype, "create", null); ], FriendshipController.prototype, "create", null);
__decorate([ __decorate([
(0, common_1.Patch)(':userId/received/:relationshipId'), (0, common_1.Patch)('myfriends/:relationshipId'),
(0, common_1.UseGuards)(jwtGuards_1.JwtAuthGuard), (0, common_1.UseGuards)(_42guards_1.AuthenticateGuard),
__param(0, (0, common_1.Param)('friendId')), __param(0, (0, common_1.Param)('relationshipId')),
__param(1, (0, common_1.Body)()), __param(1, (0, common_1.Query)('status')),
__param(2, (0, common_1.Req)()),
__metadata("design:type", Function), __metadata("design:type", Function),
__metadata("design:paramtypes", [String, update_friendship_dto_1.UpdateFriendshipDto]), __metadata("design:paramtypes", [String, String, Object]),
__metadata("design:returntype", void 0) __metadata("design:returntype", void 0)
], FriendshipController.prototype, "update", null); ], FriendshipController.prototype, "update", null);
__decorate([ __decorate([
(0, common_1.Delete)(':userId/:friendId'), (0, common_1.Delete)('myfriends/:relationshipId'),
(0, common_1.UseGuards)(jwtGuards_1.JwtAuthGuard), (0, common_1.UseGuards)(_42guards_1.AuthenticateGuard),
__param(0, (0, common_1.Param)('friendId')), __param(0, (0, common_1.Param)('relationshipId')),
__metadata("design:type", Function), __metadata("design:type", Function),
__metadata("design:paramtypes", [String]), __metadata("design:paramtypes", [String]),
__metadata("design:returntype", void 0) __metadata("design:returntype", void 0)
], FriendshipController.prototype, "remove", null); ], FriendshipController.prototype, "remove", null);
__decorate([
(0, common_1.Get)('blocked'),
(0, common_1.UseGuards)(_42guards_1.AuthenticateGuard),
__param(0, (0, common_1.Req)()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], FriendshipController.prototype, "findAllBlocked", null);
__decorate([
(0, common_1.Get)('pending'),
(0, common_1.UseGuards)(_42guards_1.AuthenticateGuard),
__param(0, (0, common_1.Req)()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], FriendshipController.prototype, "findAllPendantFriendshipRequested", null);
__decorate([
(0, common_1.Get)('received'),
(0, common_1.UseGuards)(_42guards_1.AuthenticateGuard),
__param(0, (0, common_1.Req)()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], FriendshipController.prototype, "findAllPendantFriendshipReceived", null);
FriendshipController = __decorate([ FriendshipController = __decorate([
(0, common_1.Controller)('network'), (0, common_1.Controller)('network'),
__metadata("design:paramtypes", [friendship_service_1.FriendshipService]) __metadata("design:paramtypes", [friendship_service_1.FriendshipService])

View File

@@ -1 +1 @@
{"version":3,"file":"friendship.controller.js","sourceRoot":"","sources":["../../src/friendship/friendship.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAmI;AAEnI,2DAA4D;AAE5D,uEAAkE;AAClE,uEAAkE;AAElE,6DAAyD;AAGlD,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IAChC,YAA6B,iBAAoC;QAApC,sBAAiB,GAAjB,iBAAiB,CAAmB;IAAG,CAAC;IAIrE,SAAS,CAAkB,MAAc;QACxC,OAAO,IAAI,CAAC,iBAAiB,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;IACtD,CAAC;IAID,cAAc,CAAkB,MAAc;QAC7C,OAAO,IAAI,CAAC,iBAAiB,CAAC,qBAAqB,CAAC,MAAM,CAAC,CAAC;IAC7D,CAAC;IAID,iCAAiC,CAAkB,MAAc;QAChE,OAAO,IAAI,CAAC,iBAAiB,CAAC,mCAAmC,CAAC,MAAM,CAAC,CAAC;IAC3E,CAAC;IAID,gCAAgC,CAAkB,MAAc;QAC/D,OAAO,IAAI,CAAC,iBAAiB,CAAC,oCAAoC,CAAC,MAAM,CAAC,CAAC;IAC5E,CAAC;IAID,aAAa,CAAoB,QAAgB;QAChD,OAAO,IAAI,CAAC,iBAAiB,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;IACvD,CAA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AA,IAAA,aAAI,GAAE,CAAA;;qCAAsB,2CAAmB;;kDAEtD;AAED;IAAC,IAAA,cAAK,EAAC,kCAAkC,CAAC;IACzC,IAAA,kBAAS,EAAC,wBAAY,CAAC;IAChB,WAAA,IAAA,cAAK,EAAC,UAAU,CAAC,CAAA;IAA0B,WAAA,IAAA,aAAI,GAAE,CAAA;;6CAAW,2CAAmB;;kDAEtF;AAED;IAAC,IAAA,eAAM,EAAC,mBAAmB,CAAC;IAC3B,IAAA,kBAAS,EAAC,wBAAY,CAAC;IAChB,WAAA,IAAA,cAAK,EAAC,UAAU,CAAC,CAAA;;;;kDAExB;AAlDW,oBAAoB;IADhC,IAAA,mBAAU,EAAC,SAAS,CAAC;qCAE2B,sCAAiB;GADrD,oBAAoB,CAmDhC;AAnDY,oDAAoB"} {"version":3,"file":"friendship.controller.js","sourceRoot":"","sources":["../../src/friendship/friendship.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA+I;AAC/I,0DAAgE;AAEhE,uEAAkE;AAGlE,6DAAyD;AAGlD,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IAChC,YAA6B,iBAAoC;QAApC,sBAAiB,GAAjB,iBAAiB,CAAmB;IAAI,CAAC;IAKtE,SAAS,CAAQ,GAAG;QACnB,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC;QACtB,OAAO,IAAI,CAAC,iBAAiB,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACvD,CAAC;IAKD,aAAa,CAA0B,cAAsB,EAAS,GAAG;QACxE,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC;QACtB,OAAO,IAAI,CAAC,iBAAiB,CAAC,aAAa,CAAC,cAAc,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;IACtE,CAAC;IAMD,MAAM,CAAS,mBAAwC,EAAS,GAAG;QAClE,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC;QACtB,OAAO,CAAC,G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;;;4EAGtC;AAtEW,oBAAoB;IADhC,IAAA,mBAAU,EAAC,SAAS,CAAC;qCAE2B,sCAAiB;GADrD,oBAAoB,CAuEhC;AAvEY,oDAAoB"}

View File

@@ -1,19 +1,18 @@
import { User } from 'src/users/entities/user.entity'; import { User } from 'src/users/entities/user.entity';
import { Repository } from 'typeorm'; import { Repository } from 'typeorm';
import { CreateFriendshipDto } from './dto/create-friendship.dto'; import { CreateFriendshipDto } from './dto/create-friendship.dto';
import { UpdateFriendshipDto } from './dto/update-friendship.dto';
import { Friendship } from './entities/friendship.entity'; import { Friendship } from './entities/friendship.entity';
export declare class FriendshipService { export declare class FriendshipService {
private readonly friendshipRepository; private readonly friendshipRepository;
private readonly userRepository; private readonly userRepository;
constructor(friendshipRepository: Repository<Friendship>, userRepository: Repository<User>); constructor(friendshipRepository: Repository<Friendship>, userRepository: Repository<User>);
findOneFriend(id: string): Promise<Friendship[]>; findOneFriend(friendshipId: string, userId: string): Promise<Friendship[]>;
findOneBlocked(id: string): Promise<Friendship[]>; findOneBlocked(friendshipId: string): Promise<Friendship[]>;
findAllFriends(id: string): Promise<Friendship[]>; findAllFriends(userId: string): Promise<Friendship[]>;
findAllBlockedFriends(id: string): Promise<Friendship[]>; findAllBlockedFriends(userId: string): Promise<Friendship[]>;
findAllPendantRequestsForFriendship(id: string): Promise<Friendship[]>; findAllPendantRequestsForFriendship(userId: string): Promise<Friendship[]>;
findAllReceivedRequestsForFriendship(id: string): Promise<Friendship[]>; findAllReceivedRequestsForFriendship(userId: string): Promise<Friendship[]>;
create(createFriendshipDto: CreateFriendshipDto): Promise<Friendship>; create(createFriendshipDto: CreateFriendshipDto, creator: User): Promise<Friendship>;
updateFriendship(id: string, updateFriendshipDto: UpdateFriendshipDto): Promise<Friendship>; updateFriendship(relationshipId: string, user: User, status: string): Promise<Friendship>;
removeFriendship(id: string): Promise<Friendship[]>; removeFriendship(relationshipId: string): Promise<Friendship>;
} }

View File

@@ -23,60 +23,57 @@ let FriendshipService = class FriendshipService {
this.friendshipRepository = friendshipRepository; this.friendshipRepository = friendshipRepository;
this.userRepository = userRepository; this.userRepository = userRepository;
} }
async findOneFriend(id) { async findOneFriend(friendshipId, userId) {
const friendship = await this.friendshipRepository.find({ where: { id: +id, status: friendship_entity_1.FriendshipStatus.ACCEPTED } }); const friendship = await this.friendshipRepository.find({ where: { id: +friendshipId, requesterId: userId, status: friendship_entity_1.FriendshipStatus.ACCEPTED } });
if (!friendship) if (!friendship)
throw new common_1.HttpException(`The requested friend not found.`, common_1.HttpStatus.NOT_FOUND); throw new common_1.HttpException(`The requested friend not found.`, common_1.HttpStatus.NOT_FOUND);
return friendship; return friendship;
} }
async findOneBlocked(id) { async findOneBlocked(friendshipId) {
const friendship = await this.friendshipRepository.find({ where: { id: +id, status: friendship_entity_1.FriendshipStatus.BLOCKED } }); const friendship = await this.friendshipRepository.find({ where: { id: +friendshipId, status: friendship_entity_1.FriendshipStatus.BLOCKED } });
if (!friendship) if (!friendship)
throw new common_1.HttpException(`The requested friend not found.`, common_1.HttpStatus.NOT_FOUND); throw new common_1.HttpException(`The requested user not found.`, common_1.HttpStatus.NOT_FOUND);
return friendship; return friendship;
} }
async findAllFriends(id) { async findAllFriends(userId) {
const user = await this.userRepository.findOneBy({ id: +id }); const friendship = await this.friendshipRepository
if (!user) .createQueryBuilder('friendship')
throw new common_1.HttpException(`The requested user not found.`, common_1.HttpStatus.NOT_FOUND); .where('friendship.status = :status', { status: friendship_entity_1.FriendshipStatus.ACCEPTED })
const friends = await this.friendshipRepository.find({ where: { requesterId: id, status: friendship_entity_1.FriendshipStatus.ACCEPTED } }); .andWhere('friendship.addresseeId = :addressee', { addressee: userId })
return friends; .orWhere('friendship.requesterId = :requester', { requester: userId })
.andWhere('friendship.status = :status', { status: friendship_entity_1.FriendshipStatus.ACCEPTED })
.getMany();
for (const friend of friendship)
console.log("FRIENDSHIP : " + friend.status);
return friendship;
} }
async findAllBlockedFriends(id) { async findAllBlockedFriends(userId) {
const user = await this.userRepository.findOneBy({ id: +id }); return await this.friendshipRepository
if (!user) .createQueryBuilder('friendship')
throw new common_1.HttpException(`The requested user not found.`, common_1.HttpStatus.NOT_FOUND); .where('friendship.requesterId = :requestee', { requestee: userId })
const blocked = await this.friendshipRepository.find({ where: { requesterId: id, status: friendship_entity_1.FriendshipStatus.BLOCKED } }); .orWhere('friendship.addresseeId = :addressee', { addressee: userId })
return blocked; .andWhere('friendship.status = :status', { status: friendship_entity_1.FriendshipStatus.BLOCKED })
.getMany();
} }
async findAllPendantRequestsForFriendship(id) { async findAllPendantRequestsForFriendship(userId) {
const user = await this.userRepository.findOneBy({ id: +id }); return await this.friendshipRepository
if (!user) .createQueryBuilder('friendship')
throw new common_1.HttpException(`The requested user not found.`, common_1.HttpStatus.NOT_FOUND); .where('friendship.requesterId = :requestee', { requestee: userId })
const requests = await this.friendshipRepository.find({ .andWhere('friendship.status = :status', { status: friendship_entity_1.FriendshipStatus.REQUESTED })
where: { requesterId: id, status: friendship_entity_1.FriendshipStatus.REQUESTED }, .getMany();
relations: ['requesterId']
});
return requests;
} }
async findAllReceivedRequestsForFriendship(id) { async findAllReceivedRequestsForFriendship(userId) {
const user = await this.userRepository.findOneBy({ id: +id }); return await this.friendshipRepository
if (!user) .createQueryBuilder('friendship')
throw new common_1.HttpException(`The requested user not found.`, common_1.HttpStatus.NOT_FOUND); .where('friendship.addresseeId = :addressee', { addressee: userId })
const requests = await this.friendshipRepository.find({ .andWhere('friendship.status = :status', { status: friendship_entity_1.FriendshipStatus.REQUESTED })
where: { addresseeId: id, status: friendship_entity_1.FriendshipStatus.REQUESTED }, .getMany();
relations: ['addresseeId']
});
return requests;
} }
async create(createFriendshipDto) { async create(createFriendshipDto, creator) {
const requester = await this.userRepository.findOneBy({ id: +createFriendshipDto.requesterId });
if (!requester)
throw new common_1.HttpException(`The user does not exist.`, common_1.HttpStatus.NOT_FOUND);
const addressee = await this.userRepository.findOneBy({ id: +createFriendshipDto.addresseeId }); const addressee = await this.userRepository.findOneBy({ id: +createFriendshipDto.addresseeId });
if (!addressee) if (!addressee)
throw new common_1.HttpException(`The user does not exist.`, common_1.HttpStatus.NOT_FOUND); throw new common_1.HttpException(`The addressee does not exist.`, common_1.HttpStatus.NOT_FOUND);
if (createFriendshipDto.requesterId == createFriendshipDto.addresseeId) if (creator.id === addressee.id)
throw new common_1.HttpException(`You can't add yourself.`, common_1.HttpStatus.NOT_FOUND); throw new common_1.HttpException(`You can't add yourself.`, common_1.HttpStatus.NOT_FOUND);
const friendship = await this.friendshipRepository.findOneBy({ requesterId: createFriendshipDto.requesterId, addresseeId: createFriendshipDto.addresseeId }); const friendship = await this.friendshipRepository.findOneBy({ requesterId: createFriendshipDto.requesterId, addresseeId: createFriendshipDto.addresseeId });
if (friendship) { if (friendship) {
@@ -85,21 +82,31 @@ let FriendshipService = class FriendshipService {
else if (friendship.status && friendship.status === friendship_entity_1.FriendshipStatus.REQUESTED) else if (friendship.status && friendship.status === friendship_entity_1.FriendshipStatus.REQUESTED)
throw new common_1.HttpException(`The friendship request has already been sent the ${friendship.date}.`, common_1.HttpStatus.OK); throw new common_1.HttpException(`The friendship request has already been sent the ${friendship.date}.`, common_1.HttpStatus.OK);
else if (friendship.status && friendship.status === friendship_entity_1.FriendshipStatus.BLOCKED) else if (friendship.status && friendship.status === friendship_entity_1.FriendshipStatus.BLOCKED)
throw new common_1.HttpException(``, common_1.HttpStatus.OK); throw new common_1.HttpException(`We can't do that`, common_1.HttpStatus.OK);
else if (friendship.status && friendship.status === friendship_entity_1.FriendshipStatus.DECLINED) else if (friendship.status && friendship.status === friendship_entity_1.FriendshipStatus.DECLINED)
throw new common_1.HttpException(`The request has been declined.`, common_1.HttpStatus.OK); throw new common_1.HttpException(`The request has been declined.`, common_1.HttpStatus.OK);
} }
const newFriendship = this.friendshipRepository.create({ requesterId: createFriendshipDto.requesterId, addresseeId: createFriendshipDto.addresseeId, status: friendship_entity_1.FriendshipStatus.REQUESTED }); const newFriendship = this.friendshipRepository.create({ requesterId: createFriendshipDto.requesterId, addresseeId: createFriendshipDto.addresseeId, status: friendship_entity_1.FriendshipStatus.REQUESTED });
return this.friendshipRepository.save(newFriendship); return this.friendshipRepository.save(newFriendship);
} }
async updateFriendship(id, updateFriendshipDto) { async updateFriendship(relationshipId, user, status) {
const friendship = await this.friendshipRepository.preload(Object.assign({ id: +id }, updateFriendshipDto)); const relation = await this.friendshipRepository.findOneBy({ id: +relationshipId });
if (!friendship) if (!relation)
throw new common_1.HttpException(`The friendship could not be updated.`, common_1.HttpStatus.NOT_FOUND); throw new common_1.HttpException(`The requested relationship not found.`, common_1.HttpStatus.NOT_FOUND);
return this.friendshipRepository.save(friendship); if (status === friendship_entity_1.FriendshipStatus.ACCEPTED)
relation.status = friendship_entity_1.FriendshipStatus.ACCEPTED;
else if (status === friendship_entity_1.FriendshipStatus.DECLINED)
relation.status = friendship_entity_1.FriendshipStatus.DECLINED;
else if (status === friendship_entity_1.FriendshipStatus.BLOCKED)
relation.status = friendship_entity_1.FriendshipStatus.BLOCKED;
else
throw new common_1.HttpException(`The status is not valid.`, common_1.HttpStatus.NOT_FOUND);
if (relation.status !== status)
throw new common_1.HttpException(`We could not update the status.`, common_1.HttpStatus.OK);
return this.friendshipRepository.save(relation);
} }
async removeFriendship(id) { async removeFriendship(relationshipId) {
const friendship = await this.findOneFriend(id); const friendship = await this.friendshipRepository.findOneBy({ id: +relationshipId });
if (!friendship) if (!friendship)
throw new common_1.HttpException(`Your friend could not be deleted.`, common_1.HttpStatus.NOT_FOUND); throw new common_1.HttpException(`Your friend could not be deleted.`, common_1.HttpStatus.NOT_FOUND);
return this.friendshipRepository.remove(friendship); return this.friendshipRepository.remove(friendship);

View File

@@ -1 +1 @@
{"version":3,"file":"friendship.service.js","sourceRoot":"","sources":["../../src/friendship/friendship.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAuE;AACvE,6CAAmD;AACnD,+DAAsD;AACtD,qCAAqC;AAGrC,oEAA4E;AAGrE,I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@ async function bootstrap() {
client.connect(); client.connect();
const RedisStore = connectRedis(session); const RedisStore = connectRedis(session);
client.on('connect', () => { client.on('connect', () => {
console.log("Redis Connected"); console.log("Redis successfully Connected");
}); });
app.useGlobalPipes(new common_1.ValidationPipe({ app.useGlobalPipes(new common_1.ValidationPipe({
whitelist: true, whitelist: true,

View File

@@ -1 +1 @@
{"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";;AAAA,uCAA2C;AAC3C,2CAAgD;AAChD,6CAAyC;AACzC,2CAA2C;AAC3C,qCAAqC;AACrC,+BAA+B;AAC/B,8CAA8C;AAE9C,KAAK,UAAU,SAAS;IACvB,MAAM,GAAG,GAAG,MAAM,kBAAW,CAAC,MAAM,CAAC,sBAAS,CAAC,CAAC;IAChD,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,IAAI,CAAC;IACtC,MAAM,MAAM,GAAG,KAAK,CAAC,YAAY,CAChC;QACC,MAAM,EAAE,EAAE,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,IAAI,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE;QAChF,UAAU,EAAE,IAAI;KAChB,CACD,CAAC;IACF,MAAM,CAAC,OAAO,EAAE,CAAC;IACjB,MAAM,UAAU,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;IACzC,MAAM,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE;QACzB,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;IAChC,CAAC,CAAC,CAAC;IAIH,GAAG,CAAC,cAAc,CACjB,IAAI,uBAAc,CAAC;QAElB,SAAS,EAAE,IAAI;QAEf,oBAAoB,EAAE,IAAI;QAE1B,SAAS,EAAE,IAAI;QACf,gBAAgB,EAAE;YACjB,wBAAwB,EAAE,IAAI;SAC9B;KACD,CAAC,CACF,CAAC;IACF,GAAG,CAAC,eAAe,CAAC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U,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;IACzC,MAAM,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE;QACzB,OAAO,CAAC,GAAG,CAAC,8BAA8B,CAAC,CAAC;IAC7C,CAAC,CAAC,CAAC;IAIH,GAAG,CAAC,cAAc,CACjB,IAAI,uBAAc,CAAC;QAElB,SAAS,EAAE,IAAI;QAEf,oBAAoB,EAAE,IAAI;QAE1B,SAAS,EAAE,IAAI;QACf,gBAAgB,EAAE;YACjB,wBAAwB,EAAE,IAAI;SAC9B;KACD,CAAC,CACF,CAAC;IACF,GAAG,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;IAC9B,GAAG,CAAC,GAAG,CACN,OAAO,CAAC;QACP,MAAM,EAAE;YACP,MAAM,EAAE,OAAO,GAAG,EAAE;SACpB;QACD,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,aAAa;QACjC,MAAM,EAAE,KAAK;QACb,iBAAiB,EAAE,KAAK;QACxB,KAAK,EAAE,IAAI,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;KACjC,CAAC,CACF,CAAC;IACF,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC;IAC/B,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;IAC5B,MAAM,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC,qBAAqB,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC7E,CAAC;AACD,SAAS,EAAE,CAAC"}

File diff suppressed because one or more lines are too long

View File

@@ -1,6 +1,6 @@
export declare class CreateUsersDto { export declare class CreateUsersDto {
readonly username: string; readonly username: string;
readonly fourtyTwoId: string; readonly fortyTwoId: string;
readonly email: string; readonly email: string;
readonly image_url: string; readonly image_url: string;
} }

View File

@@ -20,7 +20,7 @@ __decorate([
__decorate([ __decorate([
(0, class_validator_1.IsString)(), (0, class_validator_1.IsString)(),
__metadata("design:type", String) __metadata("design:type", String)
], CreateUsersDto.prototype, "fourtyTwoId", void 0); ], CreateUsersDto.prototype, "fortyTwoId", void 0);
__decorate([ __decorate([
(0, class_validator_1.IsEmail)(), (0, class_validator_1.IsEmail)(),
__metadata("design:type", String) __metadata("design:type", String)

View File

@@ -1 +1 @@
{"version":3,"file":"create-users.dto.js","sourceRoot":"","sources":["../../../src/users/dto/create-users.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAAoD;AAGpD,MAAa,cAAc;CAS1B;AARA;IAAC,IAAA,0BAAQ,GAAE;;gDACe;AAC1B;IAAC,IAAA,0BAAQ,GAAE;;mDACkB;AAC7B;IAAC,IAAA,yBAAO,GAAE;;6CACa;AACvB;IAAC,IAAA,0BAAQ,GAAE;;iDACgB;AAR5B,wCASC"} {"version":3,"file":"create-users.dto.js","sourceRoot":"","sources":["../../../src/users/dto/create-users.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAAoD;AAGpD,MAAa,cAAc;CAS1B;AARA;IAAC,IAAA,0BAAQ,GAAE;;gDACe;AAC1B;IAAC,IAAA,0BAAQ,GAAE;;kDACiB;AAC5B;IAAC,IAAA,yBAAO,GAAE;;6CACa;AACvB;IAAC,IAAA,0BAAQ,GAAE;;iDACgB;AAR5B,wCASC"}

View File

@@ -1,7 +1,7 @@
import { Friendship } from "../../friendship/entities/friendship.entity"; import { Friendship } from "../../friendship/entities/friendship.entity";
export declare class User { export declare class User {
id: number; id: number;
fourtyTwoId: string; fortyTwoId: string;
username: string; username: string;
email: string; email: string;
image_url: string; image_url: string;

View File

@@ -22,7 +22,7 @@ __decorate([
__decorate([ __decorate([
(0, typeorm_1.Column)({ unique: true }), (0, typeorm_1.Column)({ unique: true }),
__metadata("design:type", String) __metadata("design:type", String)
], User.prototype, "fourtyTwoId", void 0); ], User.prototype, "fortyTwoId", void 0);
__decorate([ __decorate([
(0, typeorm_1.Column)(), (0, typeorm_1.Column)(),
__metadata("design:type", String) __metadata("design:type", String)

View File

@@ -1 +1 @@
{"version":3,"file":"user.entity.js","sourceRoot":"","sources":["../../../src/users/entities/user.entity.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,qDAAkD;AAClD,qCAA2G;AAC3G,mFAAyE;AAKlE,IAAM,IAAI,GAAV,MAAM,IAAI;CA+BhB,CAAA;AA7BA;IAAC,IAAA,gCAAsB,GAAE;;gCACd;AAEX;IAAC,IAAA,gBAAM,EAAC,EAAC,MAAM,EAAE,IAAI,EAAC,CAAC;;yCACH;AAEpB;IAAC,IAAA,gBAAM,GAAE;;sCACQ;AAEjB;IAAC,IAAA,gBAAM,GAAE;IACR,IAAA,yBAAO,GAAE;;mCACI;AAEd;IAAC,IAAA,gBAAM,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;uCACR;AAEnB;IAAC,IAAA,gBAAM,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;mCACb;AAEd;IAAC,IAAA,gBAAM,EAAC,MAAM,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;oCAClB;AAEjB;IAAC,IAAA,mBAAS,GAAE;IACX,IAAA,mBAAS,EAAC,IAAI,CAAC,EAAE,CAAC,8BAAU,EAAG,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,WAAW,CAAC;;yCAC7C;AAE1B;IAAC,IAAA,mBAAS,GAAE;IACX,IAAA,mBAAS,EAAC,IAAI,CAAC,EAAE,CAAC,8BAAU,EAAG,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,WAAW,CAAC;;yCAC7C;AA9Bd,IAAI;IAFhB,IAAA,gBAAM,EAAC,MAAM,CAAC;IACd,IAAA,gBAAM,EAAC,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;GACjB,IAAI,CA+BhB;AA/BY,oBAAI"} {"version":3,"file":"user.entity.js","sourceRoot":"","sources":["../../../src/users/entities/user.entity.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,qDAAkD;AAClD,qCAA2G;AAC3G,mFAAyE;AAKlE,IAAM,IAAI,GAAV,MAAM,IAAI;CA+BhB,CAAA;AA7BA;IAAC,IAAA,gCAAsB,GAAE;;gCACd;AAEX;IAAC,IAAA,gBAAM,EAAC,EAAC,MAAM,EAAE,IAAI,EAAC,CAAC;;wCACJ;AAEnB;IAAC,IAAA,gBAAM,GAAE;;sCACQ;AAEjB;IAAC,IAAA,gBAAM,GAAE;IACR,IAAA,yBAAO,GAAE;;mCACI;AAEd;IAAC,IAAA,gBAAM,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;uCACR;AAEnB;IAAC,IAAA,gBAAM,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;mCACb;AAEd;IAAC,IAAA,gBAAM,EAAC,MAAM,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;oCAClB;AAEjB;IAAC,IAAA,mBAAS,GAAE;IACX,IAAA,mBAAS,EAAC,IAAI,CAAC,EAAE,CAAC,8BAAU,EAAG,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,WAAW,CAAC;;yCAC7C;AAE1B;IAAC,IAAA,mBAAS,GAAE;IACX,IAAA,mBAAS,EAAC,IAAI,CAAC,EAAE,CAAC,8BAAU,EAAG,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,WAAW,CAAC;;yCAC7C;AA9Bd,IAAI;IAFhB,IAAA,gBAAM,EAAC,MAAM,CAAC;IACd,IAAA,gBAAM,EAAC,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;GACjB,IAAI,CA+BhB;AA/BY,oBAAI"}

View File

@@ -27,8 +27,6 @@ let UsersController = class UsersController {
return this.usersService.findAll(paginationquery); return this.usersService.findAll(paginationquery);
} }
findOne(req) { findOne(req) {
console.log('INSIDE USER CONTROLLER');
console.log(req.user);
return this.usersService.findOne(req.user.id); return this.usersService.findOne(req.user.id);
} }
create(createUsersDto) { create(createUsersDto) {
@@ -67,8 +65,8 @@ __decorate([
__metadata("design:returntype", void 0) __metadata("design:returntype", void 0)
], UsersController.prototype, "create", null); ], UsersController.prototype, "create", null);
__decorate([ __decorate([
(0, common_1.Patch)(),
(0, common_1.UseGuards)(_42guards_1.AuthenticateGuard), (0, common_1.UseGuards)(_42guards_1.AuthenticateGuard),
(0, common_1.Patch)(),
__param(0, (0, common_1.Req)()), __param(0, (0, common_1.Req)()),
__param(1, (0, common_1.Body)()), __param(1, (0, common_1.Body)()),
__metadata("design:type", Function), __metadata("design:type", Function),
@@ -76,8 +74,8 @@ __decorate([
__metadata("design:returntype", void 0) __metadata("design:returntype", void 0)
], UsersController.prototype, "update", null); ], UsersController.prototype, "update", null);
__decorate([ __decorate([
(0, common_1.Delete)(':id'),
(0, common_1.UseGuards)(_42guards_1.AuthenticateGuard), (0, common_1.UseGuards)(_42guards_1.AuthenticateGuard),
(0, common_1.Delete)(),
__param(0, (0, common_1.Req)()), __param(0, (0, common_1.Req)()),
__metadata("design:type", Function), __metadata("design:type", Function),
__metadata("design:paramtypes", [Object]), __metadata("design:paramtypes", [Object]),

View File

@@ -1 +1 @@
{"version":3,"file":"users.controller.js","sourceRoot":"","sources":["../../src/users/users.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAGwB;AACxB,0DAAgE;AAChE,6EAAyE;AACzE,6DAAwD;AACxD,6DAAwD;AAExD,mDAA+C;AAIxC,IAAM,eAAe,GAArB,MAAM,eAAe;IAC3B,YAA6B,YAA0B;QAA1B,iBAAY,GAAZ,YAAY,CAAc;IAAG,CAAC;IAK3D,OAAO,CAAU,eAAoC;QAEpD,OAAO,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;IACnD,CAAC;IAID,OAAO,CAAQ,GAAG;QACjB,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC;QACtC,OAAO,CAAC,GAAG,CAAC,GAAG,C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5B,IAAA,YAAG,GAAE;IACG,WAAA,IAAA,YAAG,GAAE,CAAA;;;;8CAEb;AAED;IAAC,IAAA,kBAAS,EAAC,6BAAiB,CAAC;IAC5B,IAAA,aAAI,GAAE;IACN,IAAA,iBAAQ,EAAC,mBAAU,CAAC,OAAO,CAAC;IACrB,WAAA,IAAA,aAAI,GAAE,CAAA;;qCAAkB,iCAAc;;6CAE7C;AAED;IAAC,IAAA,kBAAS,EAAC,6BAAiB,CAAC;IAC5B,IAAA,cAAK,GAAE;IACA,WAAA,IAAA,YAAG,GAAE,CAAA;IAAO,WAAA,IAAA,aAAI,GAAE,CAAA;;6CAAiB,iCAAc;;6CAExD;AAED;IAAC,IAAA,kBAAS,EAAC,6BAAiB,CAAC;IAC5B,IAAA,eAAM,GAAE;IACD,WAAA,IAAA,YAAG,GAAE,CAAA;;;;6CAEZ;AA3CW,eAAe;IAD3B,IAAA,mBAAU,EAAC,MAAM,CAAC;qCAEyB,4BAAY;GAD3C,eAAe,CA4C3B;AA5CY,0CAAe"}

View File

@@ -8,7 +8,7 @@ export declare class UsersService {
private readonly userRepository; private readonly userRepository;
private readonly friendshipRepository; private readonly friendshipRepository;
constructor(userRepository: Repository<User>, friendshipRepository: Repository<Friendship>); constructor(userRepository: Repository<User>, friendshipRepository: Repository<Friendship>);
findOneByFourtyTwoId(fourtytwo_id: string): Promise<User>; findOneByFourtyTwoId(fortytwo_id: string): Promise<User>;
findOne(id: string): Promise<User>; findOne(id: string): Promise<User>;
findAll(paginationquery: PaginationQueryDto): Promise<User[]>; findAll(paginationquery: PaginationQueryDto): Promise<User[]>;
create(createUserDto: CreateUsersDto): Promise<User>; create(createUserDto: CreateUsersDto): Promise<User>;

View File

@@ -18,17 +18,13 @@ const typeorm_1 = require("@nestjs/typeorm");
const user_entity_1 = require("./entities/user.entity"); const user_entity_1 = require("./entities/user.entity");
const typeorm_2 = require("typeorm"); const typeorm_2 = require("typeorm");
const friendship_entity_1 = require("../friendship/entities/friendship.entity"); const friendship_entity_1 = require("../friendship/entities/friendship.entity");
const class_validator_1 = require("class-validator");
let UsersService = class UsersService { let UsersService = class UsersService {
constructor(userRepository, friendshipRepository) { constructor(userRepository, friendshipRepository) {
this.userRepository = userRepository; this.userRepository = userRepository;
this.friendshipRepository = friendshipRepository; this.friendshipRepository = friendshipRepository;
} }
async findOneByFourtyTwoId(fourtytwo_id) { async findOneByFourtyTwoId(fortytwo_id) {
console.log(`Find user with fourtytwo_id ${fourtytwo_id}`); const user = await this.userRepository.findOneBy({ fortyTwoId: fortytwo_id });
if (!(0, class_validator_1.isNumberString)(fourtytwo_id))
throw new common_1.HttpException(`The requested user not found.`, common_1.HttpStatus.NOT_FOUND);
const user = await this.userRepository.findOneBy({ fourtyTwoId: fourtytwo_id });
if (!user) { if (!user) {
console.log(`The requested user not found.`); console.log(`The requested user not found.`);
return null; return null;
@@ -50,8 +46,7 @@ let UsersService = class UsersService {
}); });
} }
async create(createUserDto) { async create(createUserDto) {
console.log(`Create user with ${createUserDto}`); if (await this.userRepository.findOneBy({ fortyTwoId: createUserDto.fortyTwoId }))
if (await this.userRepository.findOneBy({ fourtyTwoId: createUserDto.fourtyTwoId }))
throw new common_1.HttpException(`The user already exists.`, common_1.HttpStatus.CONFLICT); throw new common_1.HttpException(`The user already exists.`, common_1.HttpStatus.CONFLICT);
const user = this.userRepository.create(createUserDto); const user = this.userRepository.create(createUserDto);
if (!user) if (!user)

View File

@@ -1 +1 @@
{"version":3,"file":"users.service.js","sourceRoot":"","sources":["../../src/users/users.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAsG;AACtG,6CAAmD;AAEnD,wDAA8C;AAC9C,qCAA8D;AAG9D,gFAAsE;AACtE,qDAAiD;AAM1C,IAAM,YAAY,GAAlB,MAAM,YAAY;IAExB,YAEiB,cAAgC,EAEhC,oBAA4C;QAF5C,mBAAc,GAAd,cAAc,CAAkB;QAEhC,yBAAoB,GAApB,oBAAoB,CAAwB;IAC1D,CAAC;IAEJ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,oBAAU;QAEJ,oBAAU;GANrC,YAAY,CA6DxB;AA7DY,oCAAY"}

View File

@@ -13,7 +13,7 @@ export class AuthenticationService {
async validateUser(createUsersDto :CreateUsersDto){ async validateUser(createUsersDto :CreateUsersDto){
console.log("Validate inside authentication.service.ts"); console.log("Validate inside authentication.service.ts");
const user = await this.userService.findOneByFourtyTwoId(createUsersDto.fourtyTwoId); const user = await this.userService.findOneByFourtyTwoId(createUsersDto.fortyTwoId);
if (user) if (user)
return user; return user;
return this.userService.create(createUsersDto); return this.userService.create(createUsersDto);

View File

@@ -18,7 +18,7 @@ export class FortyTwoStrategy extends PassportStrategy(Strategy, "42") {
async validate(accessToken: string, refreshToken: string, profile: Profile, callbackURL: string) { async validate(accessToken: string, refreshToken: string, profile: Profile, callbackURL: string) {
console.log("Validate inside strategy.ts"); console.log("Validate inside strategy.ts");
console.log(profile.id, profile.username, profile.phoneNumbers[0].value, profile.emails[0].value, profile.photos[0].value); console.log(profile.id, profile.username, profile.phoneNumbers[0].value, profile.emails[0].value, profile.photos[0].value);
const userDTO: CreateUsersDto = { fourtyTwoId: profile.id, username: profile.username, email: profile.emails[0].value, image_url: profile.photos[0].value }; const userDTO: CreateUsersDto = { fortyTwoId: profile.id, username: profile.username, email: profile.emails[0].value, image_url: profile.photos[0].value };
const user = await this.authenticationService.validateUser(userDTO); const user = await this.authenticationService.validateUser(userDTO);
if (!user) if (!user)
throw new UnauthorizedException(); throw new UnauthorizedException();

View File

@@ -14,7 +14,7 @@ export class SessionSerializer extends PassportSerializer {
} }
async deserializeUser(user : User, done : (err : Error, user : User) => void){ async deserializeUser(user : User, done : (err : Error, user : User) => void){
const userDB = await this.authservice.findUser(user.fourtyTwoId); const userDB = await this.authservice.findUser(user.fortyTwoId);
if (userDB) if (userDB)
done(null, userDB); done(null, userDB);
else else

View File

@@ -17,7 +17,6 @@ export class Friendship {
@CreateDateColumn() @CreateDateColumn()
date : Date; date : Date;
@Column() @Column()
@ManyToOne(type => User, user => user.requesterId) @ManyToOne(type => User, user => user.requesterId)
requesterId: string; requesterId: string;

View File

@@ -1,7 +1,6 @@
import { Body, Controller, Delete, Get, HttpCode, HttpException, HttpStatus, Param, Patch, Post, UseGuards } from '@nestjs/common'; import { Body, Controller, Delete, Get, HttpCode, HttpException, HttpStatus, Param, Patch, Post, Query, Req, UseGuards } from '@nestjs/common';
import { FortyTwoAuthGuard } from 'src/auth/42/guards/42guards'; import { AuthenticateGuard } from 'src/auth/42/guards/42guards';
import { JwtAuthGuard } from 'src/auth/42/guards/jwtGuards'; import { User } from 'src/users/entities/user.entity';
import { CreateUsersDto } from 'src/users/dto/create-users.dto';
import { CreateFriendshipDto } from './dto/create-friendship.dto'; import { CreateFriendshipDto } from './dto/create-friendship.dto';
import { UpdateFriendshipDto } from './dto/update-friendship.dto'; import { UpdateFriendshipDto } from './dto/update-friendship.dto';
import { FriendshipStatus } from './entities/friendship.entity'; import { FriendshipStatus } from './entities/friendship.entity';
@@ -9,54 +8,74 @@ import { FriendshipService } from './friendship.service';
@Controller('network') @Controller('network')
export class FriendshipController { export class FriendshipController {
constructor(private readonly friendshipService: FriendshipService) {} constructor(private readonly friendshipService: FriendshipService) { }
@Get(':userId/friends') // GET http://127.0.0.1:3000/api/v2/network/myfriends
@UseGuards(JwtAuthGuard) @Get('myfriends')
findEmpty(@Param('userId') userId: string) { @UseGuards(AuthenticateGuard)
return this.friendshipService.findAllFriends(userId); findEmpty(@Req() req) {
const user = req.user;
return this.friendshipService.findAllFriends(user.id);
} }
@Get(':userId/blocked') // GET http://127.0.0.1:3000/api/v2/network/myfriends/relationshipId
@UseGuards(JwtAuthGuard) @Get('myfriends/:relationshipId')
findAllBlocked(@Param('userId') userId: string) { @UseGuards(AuthenticateGuard)
return this.friendshipService.findAllBlockedFriends(userId); findOneFriend(@Param('relationshipId') relationshipId: string, @Req() req) {
const user = req.user;
return this.friendshipService.findOneFriend(relationshipId, user.id);
} }
@Get(':userId/pending') // POST http://127.0.0.1:3000/api/v2/network/
@UseGuards(JwtAuthGuard) @Post('myfriends')
findAllPendantFriendshipRequested(@Param('userId') userId: string) {
return this.friendshipService.findAllPendantRequestsForFriendship(userId);
}
@Get(':userId/received')
@UseGuards(JwtAuthGuard)
findAllPendantFriendshipReceived(@Param('userId') userId: string) {
return this.friendshipService.findAllReceivedRequestsForFriendship(userId);
}
@Get(':userId/myfriends/:friendId')
@UseGuards(JwtAuthGuard)
findOneFriend(@Param('friendId') friendId: string) {
return this.friendshipService.findOneFriend(friendId);
}
@Post()
@HttpCode(HttpStatus.CREATED) @HttpCode(HttpStatus.CREATED)
@UseGuards(JwtAuthGuard) @UseGuards(AuthenticateGuard)
create(@Body() createFriendshipDto: CreateFriendshipDto) { create(@Body() createFriendshipDto: CreateFriendshipDto, @Req() req) {
return this.friendshipService.create(createFriendshipDto); const user = req.user;
console.log(`User id: ${user.id}\n Friend id: ${createFriendshipDto.requesterId}`);
if (user.id === +createFriendshipDto.requesterId)
return this.friendshipService.create(createFriendshipDto, user);
return new HttpException('You can\'t request a frienship for another user', HttpStatus.FORBIDDEN);
} }
@Patch(':userId/received/:relationshipId') // PATCH http://127.0.0.1:3000/api/v2/network/myfriends/relationshipId?status=A
@UseGuards(JwtAuthGuard) @Patch('myfriends/:relationshipId')
update(@Param('friendId') relationshipId: string, @Body() {status}: UpdateFriendshipDto) { @UseGuards(AuthenticateGuard)
return this.friendshipService.updateFriendship(relationshipId, {status}); update(@Param('relationshipId') relationshipId: string, @Query('status') status : string, @Req() req)
{
const user : User = req.user;
return this.friendshipService.updateFriendship(relationshipId, user, status);
} }
@Delete(':userId/:friendId') // DELETE http://127.0.0.1:3000/api/v2/network/myfriends/relationshipId
@UseGuards(JwtAuthGuard) @Delete('myfriends/:relationshipId')
remove(@Param('friendId') friendId: string) { @UseGuards(AuthenticateGuard)
return this.friendshipService.removeFriendship(friendId); remove(@Param('relationshipId') relationshipId: string) {
return this.friendshipService.removeFriendship(relationshipId);
}
// GET http://127.0.0.1:3000/api/v2/network/blocked
@Get('blocked')
@UseGuards(AuthenticateGuard)
findAllBlocked(@Req() req) {
const user = req.user;
return this.friendshipService.findAllBlockedFriends(user.id);
}
// GET http://127.0.0.1:3000/api/v2/network/pending
@Get('pending')
@UseGuards(AuthenticateGuard)
findAllPendantFriendshipRequested(@Req() req) {
const user = req.user;
return this.friendshipService.findAllPendantRequestsForFriendship(user.id);
}
// GET http://127.0.0.1:3000/api/v2/network/received
@Get('received')
@UseGuards(AuthenticateGuard)
findAllPendantFriendshipReceived(@Req() req) {
const user = req.user;
return this.friendshipService.findAllReceivedRequestsForFriendship(user.id);
} }
} }

View File

@@ -14,102 +14,107 @@ export class FriendshipService {
private readonly friendshipRepository: Repository<Friendship>, private readonly friendshipRepository: Repository<Friendship>,
@InjectRepository(User) @InjectRepository(User)
private readonly userRepository: Repository<User>, private readonly userRepository: Repository<User>,
) {} ) { }
async findOneFriend(id: string) { async findOneFriend(friendshipId: string, userId: string) {
const friendship = await this.friendshipRepository.find({where: {id: +id, status: FriendshipStatus.ACCEPTED}}); const friendship = await this.friendshipRepository.find({ where: { id: +friendshipId, requesterId: userId, status: FriendshipStatus.ACCEPTED } });
if (!friendship) if (!friendship)
throw new HttpException(`The requested friend not found.`,HttpStatus.NOT_FOUND); throw new HttpException(`The requested friend not found.`, HttpStatus.NOT_FOUND);
return friendship; return friendship;
} }
async findOneBlocked(id: string) { async findOneBlocked(friendshipId: string) {
const friendship = await this.friendshipRepository.find({where: {id: +id, status: FriendshipStatus.BLOCKED}}); const friendship = await this.friendshipRepository.find({ where: { id: +friendshipId, status: FriendshipStatus.BLOCKED } });
if (!friendship) if (!friendship)
throw new HttpException(`The requested friend not found.`,HttpStatus.NOT_FOUND); throw new HttpException(`The requested user not found.`, HttpStatus.NOT_FOUND);
return friendship; return friendship;
} }
async findAllFriends(id: string) { async findAllFriends(userId: string) {
const user = await this.userRepository.findOneBy({id: +id}); const friendship = await this.friendshipRepository
if (!user) .createQueryBuilder('friendship')
throw new HttpException(`The requested user not found.`,HttpStatus.NOT_FOUND); .where('friendship.status = :status', { status: FriendshipStatus.ACCEPTED })
const friends = await this.friendshipRepository.find( .andWhere('friendship.addresseeId = :addressee', { addressee: userId })
{where: {requesterId: id, status: FriendshipStatus.ACCEPTED}}); .orWhere('friendship.requesterId = :requester', { requester: userId })
return friends; .andWhere('friendship.status = :status', { status: FriendshipStatus.ACCEPTED })
.getMany();
for (const friend of friendship)
console.log("FRIENDSHIP : " + friend.status);
return friendship;
} }
async findAllBlockedFriends(id: string) { async findAllBlockedFriends(userId: string) {
const user = await this.userRepository.findOneBy({id: +id}); return await this.friendshipRepository
if (!user) .createQueryBuilder('friendship')
throw new HttpException(`The requested user not found.`,HttpStatus.NOT_FOUND); .where('friendship.requesterId = :requestee', { requestee: userId })
const blocked = await this.friendshipRepository.find( .orWhere('friendship.addresseeId = :addressee', { addressee: userId })
{where: {requesterId: id, status: FriendshipStatus.BLOCKED}}); .andWhere('friendship.status = :status', { status: FriendshipStatus.BLOCKED })
return blocked; .getMany();
} }
async findAllPendantRequestsForFriendship(id: string) { async findAllPendantRequestsForFriendship(userId: string) {
const user = await this.userRepository.findOneBy({id: +id}); return await this.friendshipRepository
if (!user) .createQueryBuilder('friendship')
throw new HttpException(`The requested user not found.`,HttpStatus.NOT_FOUND); .where('friendship.requesterId = :requestee', { requestee: userId })
const requests = await this.friendshipRepository.find({ .andWhere('friendship.status = :status', { status: FriendshipStatus.REQUESTED })
where: .getMany();
{requesterId: id, status: FriendshipStatus.REQUESTED},
relations: ['requesterId']});
return requests;
} }
async findAllReceivedRequestsForFriendship(id: string) { async findAllReceivedRequestsForFriendship(userId: string) {
const user = await this.userRepository.findOneBy({id: +id}); return await this.friendshipRepository
if (!user) .createQueryBuilder('friendship')
throw new HttpException(`The requested user not found.`,HttpStatus.NOT_FOUND); .where('friendship.addresseeId = :addressee', { addressee: userId })
const requests = await this.friendshipRepository.find({ .andWhere('friendship.status = :status', { status: FriendshipStatus.REQUESTED })
where: .getMany();
{addresseeId: id, status: FriendshipStatus.REQUESTED},
relations: ['addresseeId']});
return requests;
} }
//GROS CHANTIER
async create(createFriendshipDto: CreateFriendshipDto) { async create(createFriendshipDto: CreateFriendshipDto, creator : User) {
const requester = await this.userRepository.findOneBy({id : +createFriendshipDto.requesterId}); const addressee = await this.userRepository.findOneBy({ id: +createFriendshipDto.addresseeId });
if (!requester)
throw new HttpException(`The user does not exist.`,HttpStatus.NOT_FOUND);
const addressee = await this.userRepository.findOneBy({id: +createFriendshipDto.addresseeId});
if (!addressee) if (!addressee)
throw new HttpException(`The user does not exist.`,HttpStatus.NOT_FOUND); throw new HttpException(`The addressee does not exist.`, HttpStatus.NOT_FOUND);
if (createFriendshipDto.requesterId == createFriendshipDto.addresseeId) if (creator.id === addressee.id)
throw new HttpException(`You can't add yourself.`,HttpStatus.NOT_FOUND); throw new HttpException(`You can't add yourself.`, HttpStatus.NOT_FOUND);
const friendship = await this.friendshipRepository.findOneBy({requesterId: createFriendshipDto.requesterId, addresseeId: createFriendshipDto.addresseeId}); const friendship = await this.friendshipRepository.findOneBy({ requesterId: createFriendshipDto.requesterId, addresseeId: createFriendshipDto.addresseeId });
if (friendship) { if (friendship) {
if (friendship.status && friendship.status === FriendshipStatus.ACCEPTED) if (friendship.status && friendship.status === FriendshipStatus.ACCEPTED)
throw new HttpException(`The friendship request has already been accepted.`,HttpStatus.OK); throw new HttpException(`The friendship request has already been accepted.`, HttpStatus.OK);
else if (friendship.status && friendship.status === FriendshipStatus.REQUESTED) else if (friendship.status && friendship.status === FriendshipStatus.REQUESTED)
throw new HttpException(`The friendship request has already been sent the ${friendship.date}.`,HttpStatus.OK); throw new HttpException(`The friendship request has already been sent the ${friendship.date}.`, HttpStatus.OK);
else if (friendship.status && friendship.status === FriendshipStatus.BLOCKED) else if (friendship.status && friendship.status === FriendshipStatus.BLOCKED)
throw new HttpException(``,HttpStatus.OK); throw new HttpException(`We can't do that`, HttpStatus.OK);
else if (friendship.status && friendship.status === FriendshipStatus.DECLINED) else if (friendship.status && friendship.status === FriendshipStatus.DECLINED)
throw new HttpException(`The request has been declined.`,HttpStatus.OK); throw new HttpException(`The request has been declined.`, HttpStatus.OK);
} }
const newFriendship = this.friendshipRepository.create( const newFriendship = this.friendshipRepository.create(
{requesterId: createFriendshipDto.requesterId, addresseeId: createFriendshipDto.addresseeId, status: FriendshipStatus.REQUESTED}); { requesterId: createFriendshipDto.requesterId, addresseeId: createFriendshipDto.addresseeId, status: FriendshipStatus.REQUESTED });
return this.friendshipRepository.save(newFriendship); return this.friendshipRepository.save(newFriendship);
} }
async updateFriendship(id: string, updateFriendshipDto: UpdateFriendshipDto) { async updateFriendship(relationshipId: string, user: User, status: string) {
const relation = await this.friendshipRepository.findOneBy({ id: +relationshipId });
const friendship = await this.friendshipRepository.preload( if (!relation)
{id: +id, throw new HttpException(`The requested relationship not found.`, HttpStatus.NOT_FOUND);
...updateFriendshipDto}); // if (+relation.requesterId === user.id) {
if (!friendship) // throw new HttpException(`You can't accept your own request.`, HttpStatus.NOT_FOUND);
throw new HttpException(`The friendship could not be updated.`,HttpStatus.NOT_FOUND); // }
return this.friendshipRepository.save(friendship); if (status === FriendshipStatus.ACCEPTED)
relation.status = FriendshipStatus.ACCEPTED;
else if (status === FriendshipStatus.DECLINED)
relation.status = FriendshipStatus.DECLINED;
else if (status === FriendshipStatus.BLOCKED)
relation.status = FriendshipStatus.BLOCKED;
else
throw new HttpException(`The status is not valid.`, HttpStatus.NOT_FOUND);
if (relation.status !== status)
throw new HttpException(`We could not update the status.`, HttpStatus.OK);
return this.friendshipRepository.save(relation);
} }
async removeFriendship(id: string) { async removeFriendship(relationshipId: string) {
const friendship = await this.findOneFriend(id); const friendship = await this.friendshipRepository.findOneBy({ id: +relationshipId });
if (!friendship) if (!friendship)
throw new HttpException(`Your friend could not be deleted.`,HttpStatus.NOT_FOUND); throw new HttpException(`Your friend could not be deleted.`, HttpStatus.NOT_FOUND);
return this.friendshipRepository.remove(friendship); return this.friendshipRepository.remove(friendship);
} }
} }

View File

@@ -18,7 +18,7 @@ async function bootstrap() {
client.connect(); client.connect();
const RedisStore = connectRedis(session); const RedisStore = connectRedis(session);
client.on('connect', () => { client.on('connect', () => {
console.log("Redis Connected"); console.log("Redis successfully Connected");
}); });
// module afin de créer un pipe de validation qui va nous aider // module afin de créer un pipe de validation qui va nous aider

View File

@@ -5,7 +5,7 @@ export class CreateUsersDto {
@IsString() @IsString()
readonly username: string; readonly username: string;
@IsString() @IsString()
readonly fourtyTwoId: string; readonly fortyTwoId: string;
@IsEmail() @IsEmail()
readonly email: string; readonly email: string;
@IsString() @IsString()

View File

@@ -12,7 +12,7 @@ export class User {
id: number; id: number;
@Column({unique: true}) @Column({unique: true})
fourtyTwoId: string; fortyTwoId: string;
@Column() @Column()
username: string; username: string;

View File

@@ -1,6 +1,6 @@
import { import {
Body, Controller, Delete, Get, HttpCode, Body, Controller, Delete, Get, HttpCode,
HttpStatus, Patch, Post, Query, Req, UseGuards HttpStatus, Param, Patch, Post, Query, Req, UseGuards
} from '@nestjs/common'; } from '@nestjs/common';
import { AuthenticateGuard } from 'src/auth/42/guards/42guards'; import { AuthenticateGuard } from 'src/auth/42/guards/42guards';
import { PaginationQueryDto } from 'src/common/dto/pagination-query.dto'; import { PaginationQueryDto } from 'src/common/dto/pagination-query.dto';
@@ -22,11 +22,18 @@ export class UsersController {
return this.usersService.findAll(paginationquery); return this.usersService.findAll(paginationquery);
} }
////////////////////////////////////////////////////////
///////////////////////// RUD //////////////////////////
////////////////////////////////////////////////////////
/**
* On ne fait de création via une route
* car un utilisateur est crée à la première connexion avec l'Oauth de 42.
*/
@UseGuards(AuthenticateGuard) @UseGuards(AuthenticateGuard)
@Get() @Get()
findOne(@Req() req) { findOne(@Req() req) {
console.log('INSIDE USER CONTROLLER');
console.log(req.user);
return this.usersService.findOne(req.user.id); return this.usersService.findOne(req.user.id);
} }
@@ -37,14 +44,14 @@ export class UsersController {
return this.usersService.create(createUsersDto); return this.usersService.create(createUsersDto);
} }
@Patch()
@UseGuards(AuthenticateGuard) @UseGuards(AuthenticateGuard)
@Patch()
update(@Req() req, @Body() usersUpdateDto: UpdateUsersDto) { update(@Req() req, @Body() usersUpdateDto: UpdateUsersDto) {
return this.usersService.update(req.user.id, usersUpdateDto); return this.usersService.update(req.user.id, usersUpdateDto);
} }
@Delete(':id')
@UseGuards(AuthenticateGuard) @UseGuards(AuthenticateGuard)
@Delete()
remove(@Req() req) { remove(@Req() req) {
return this.usersService.remove(req.user.id); return this.usersService.remove(req.user.id);
} }

View File

@@ -21,11 +21,8 @@ export class UsersService {
private readonly friendshipRepository: Repository<Friendship>, private readonly friendshipRepository: Repository<Friendship>,
) {} ) {}
async findOneByFourtyTwoId(fourtytwo_id: string) { async findOneByFourtyTwoId(fortytwo_id: string) {
console.log(`Find user with fourtytwo_id ${fourtytwo_id}`); const user = await this.userRepository.findOneBy({fortyTwoId: fortytwo_id});
if (!isNumberString(fourtytwo_id))
throw new HttpException(`The requested user not found.`,HttpStatus.NOT_FOUND);
const user = await this.userRepository.findOneBy({fourtyTwoId: fourtytwo_id});
if (!user) if (!user)
{ {
console.log(`The requested user not found.`); console.log(`The requested user not found.`);
@@ -52,8 +49,7 @@ export class UsersService {
} }
async create(createUserDto: CreateUsersDto) { async create(createUserDto: CreateUsersDto) {
console.log(`Create user with ${createUserDto}`); if (await this.userRepository.findOneBy({fortyTwoId: createUserDto.fortyTwoId}))
if (await this.userRepository.findOneBy({fourtyTwoId: createUserDto.fourtyTwoId}))
throw new HttpException(`The user already exists.`,HttpStatus.CONFLICT); throw new HttpException(`The user already exists.`,HttpStatus.CONFLICT);
const user = this.userRepository.create(createUserDto); const user = this.userRepository.create(createUserDto);
if (!user) if (!user)