-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
211 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Request, Response } from "express"; | ||
import { IGetUserAuthInfoRequest } from "../interfaces"; | ||
|
||
import GroupService from "../services/groups"; | ||
|
||
class GroupsController { | ||
/* | ||
Get All | ||
*/ | ||
static getAll = async (req: IGetUserAuthInfoRequest, res: Response) => { | ||
const { error, result } = await GroupService.getAll(req.uuid); | ||
if (error) { | ||
return res.status(error.code).json({ | ||
error: error.msg, | ||
}); | ||
} | ||
return res | ||
.status(200) | ||
.json(result); | ||
}; | ||
} | ||
|
||
export default GroupsController; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
import {Group } from "../entity"; | ||
|
||
export interface IGetGroups { | ||
publicGroupsWithUser: Group[] | ||
privateGroups: Group[] | ||
publicGroups: Group[] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,14 @@ | ||
export enum EMITS { | ||
// Auth | ||
LOGIN = "login", | ||
LOGIN_OF_OTHER_USER = "loginUsers", | ||
UPDATE_ACCOUNT = "UpdateAccount", | ||
UNAUTHORIZED = "unauthorized" | ||
UNAUTHORIZED = "unauthorized", | ||
|
||
// ERROR | ||
ERROR = "systemError", | ||
// Group / Chats | ||
GROUP_CREATED = "groupCreated", | ||
NEW_PUBLIC_CHAT = "newPublicChatCreated", | ||
NEW_CHAT = "newChatCreated" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Router } from "express"; | ||
import GroupsController from "../controllers/GroupsController"; | ||
import { emptySchema } from "./validations"; | ||
import { verifyToken } from "../helpers/verifyToken"; | ||
|
||
const groups = Router(); | ||
|
||
groups.get("/get_all", verifyToken, emptySchema, GroupsController.getAll); | ||
|
||
|
||
export default groups; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { | ||
createQueryBuilder, | ||
getRepository, | ||
Repository, | ||
SelectQueryBuilder, | ||
} from "typeorm"; | ||
import { Group } from "../entity"; | ||
import { IResponse, IGetGroups } from "../interfaces"; | ||
|
||
export default class UserService { | ||
public static getAll = async ( | ||
uuid: string | ||
): Promise<IResponse<IGetGroups>> => { | ||
const groupRepository: Repository<Group> = getRepository(Group); | ||
|
||
// TODO Find a better solution | ||
const privateGroups: SelectQueryBuilder<Group> = groupRepository | ||
.createQueryBuilder("group") | ||
.innerJoinAndSelect("group.users", "users", "users.uuid = :uuid", { | ||
uuid, | ||
}) | ||
.innerJoinAndSelect("group.users", "user") | ||
.where("group.private = :private", { private: true }); | ||
|
||
const publicUserGroups: SelectQueryBuilder<Group> = groupRepository | ||
.createQueryBuilder("group") | ||
.innerJoinAndSelect("group.users", "users", "users.uuid = :uuid", { | ||
uuid, | ||
}) | ||
.innerJoinAndSelect("group.users", "user") | ||
.where("group.private = :private", { private: false }); | ||
|
||
const publicGroups: SelectQueryBuilder<Group> = groupRepository | ||
.createQueryBuilder("group") | ||
.innerJoinAndSelect("group.users", "users", "users.uuid != :uuid", { | ||
uuid, | ||
}) | ||
.innerJoinAndSelect("group.users", "user") | ||
.where("group.private = :private", { private: false }); | ||
|
||
// console.log(privateGroups.getQuery()) | ||
|
||
const groupsPr = await privateGroups.getMany(); | ||
const groupsPubUser = await publicUserGroups.getMany(); | ||
const groupsPub = await publicGroups.getMany(); | ||
|
||
if (groupsPr === undefined) { | ||
return { error: { code: 404, msg: "No Records" } }; | ||
} | ||
return { | ||
result: { | ||
privateGroups: groupsPr, | ||
publicGroupsWithUser: groupsPubUser, | ||
publicGroups: groupsPub, | ||
}, | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters