Skip to content

Commit

Permalink
Merge pull request #8 from polijrorg/feat/subscription
Browse files Browse the repository at this point in the history
Feat/subscription
  • Loading branch information
tassyla authored Aug 27, 2024
2 parents 2d6d83b + 8572756 commit b70b4f5
Show file tree
Hide file tree
Showing 57 changed files with 4,514 additions and 3,906 deletions.
2 changes: 1 addition & 1 deletion docs/insomnia.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/modules/groups/dtos/ICreateGroupDTO.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
interface ICreateGroupDTO {
name: string;
description: string;
super_adm_id: string;
subscription_id: string;
}

export default ICreateGroupDTO;
1 change: 1 addition & 0 deletions src/modules/groups/dtos/IUpdateGroupDTO.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
interface IUpdateGroupDTO {
name: string;
description: string;
}

export default IUpdateGroupDTO;
11 changes: 8 additions & 3 deletions src/modules/groups/infra/http/controller/GroupsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,25 @@ export default class GroupController {
public async create(req: Request, res: Response): Promise<Response> {
const {
name,
super_adm_id,
description,
subscription_id,
} = req.body;

const { id } = req.token;

const createGroup = container.resolve(CreateGroupService);

const group = await createGroup.execute({
name,
super_adm_id,
subscription_id,
description,
super_adm_id: id,
});

return res.status(201).json(group);
}

public async readAll(req: Request, res: Response): Promise<Response> {

const readGroups = container.resolve(ReadAllGroupsService);

const groups = await readGroups.execute();
Expand All @@ -50,6 +54,7 @@ export default class GroupController {

const {
name,
description,
} = req.body;

const updateGroup = container.resolve(UpdateGroupService);
Expand Down
12 changes: 6 additions & 6 deletions src/modules/groups/infra/http/routes/groups.routes.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Router } from 'express';

import ensureAuthenticated from '@shared/infra/http/middlewares/EnsureAuthenticated';
import GroupsController from '../controller/GroupsController';

const groupsRoutes = Router();

const groupsController = new GroupsController();

groupsRoutes.post('/register', groupsController.create);
groupsRoutes.get('/read', groupsController.readAll);
groupsRoutes.get('/read/:id', groupsController.readById);
groupsRoutes.patch('/update/:id', groupsController.update);
groupsRoutes.delete('/delete/:id', groupsController.delete);
groupsRoutes.post('/register', ensureAuthenticated, groupsController.create);
groupsRoutes.get('/read', ensureAuthenticated, groupsController.readAll);
groupsRoutes.get('/read/:id', ensureAuthenticated, groupsController.readById);
groupsRoutes.patch('/update/:id', ensureAuthenticated, groupsController.update);
groupsRoutes.delete('/delete/:id', ensureAuthenticated, groupsController.delete);

export default groupsRoutes;
1 change: 1 addition & 0 deletions src/modules/groups/infra/prisma/entities/groups.prisma
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
model Groups {
id String @id @default(uuid())
name String
description String
created_at DateTime @default(now())
updated_at DateTime @default(now())
}
9 changes: 0 additions & 9 deletions src/modules/groups/infra/prisma/entities/plans.prisma

This file was deleted.

160 changes: 83 additions & 77 deletions src/modules/groups/infra/prisma/repositories/GroupsRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,96 +13,103 @@ export default class GroupsRepository implements IGroupsRepository {
}

public async create(data: ICreateGroupDTO & { include: { invited_users: { select: { email: true; name: true; }; }; }; }): Promise<Groups> {
const group = await this.ormRepository.create({
data,
include: {
invited_users: {
select: {
email: true,
name: true,
}
},
invited_emails: {
select: {
email: true,
}
},
users: {
select: {
email: true,
name: true,
}
},
adms: {
select: {
email: true,
name: true,
}
},
},
});

return group;
const group = await this.ormRepository.create({
data: {
name: data.name,
super_adm_id: data.super_adm_id,
subscription: {
connect: { id: data.subscription_id }
},
description: data.description,
},
include: {
invited_users: {
select: {
email: true,
name: true,
},
},
invited_emails: {
select: {
email: true,
},
},
users: {
select: {
email: true,
name: true,
},
},
adms: {
select: {
email: true,
name: true,
},
},
},
});

return group;
}

public async findAll(): Promise<Groups[]> {
const groups = await this.ormRepository.findMany({
include: {
invited_users: {
select: {
email: true,
name: true,
}
},
invited_emails: {
select: {
email: true,
}
},
users: {
select: {
email: true,
name: true,
}
},
adms: {
select: {
email: true,
name: true,
}
},
},
});
return groups;
}
const groups = await this.ormRepository.findMany({
include: {
invited_users: {
select: {
email: true,
name: true,
},
},
invited_emails: {
select: {
email: true,
},
},
users: {
select: {
email: true,
name: true,
},
},
adms: {
select: {
email: true,
name: true,
},
},
},
});

return groups;
}

public async findById(id: string): Promise<Groups | null> {
const group = await this.ormRepository.findFirst({
const group = await this.ormRepository.findFirst({
where: { id },
include: {
invited_users: {
select: {
email: true,
name: true,
}
},
},
invited_emails: {
select: {
email: true,
}
},
},
users: {
select: {
email: true,
name: true,
}
},
},
adms: {
select: {
email: true,
name: true,
}
},
},
},
});
Expand All @@ -111,31 +118,31 @@ export default class GroupsRepository implements IGroupsRepository {
}

public async delete(id: string): Promise<Groups> {
const group = await this.ormRepository.delete({
const group = await this.ormRepository.delete({
where: { id },
include: {
invited_users: {
select: {
email: true,
name: true,
}
},
},
invited_emails: {
select: {
email: true,
}
},
},
users: {
select: {
email: true,
name: true,
}
},
},
adms: {
select: {
email: true,
name: true,
}
},
},
},
});
Expand All @@ -144,37 +151,36 @@ export default class GroupsRepository implements IGroupsRepository {
}

public async update(id: string, data: IUpdateGroupDTO): Promise<Groups> {
const group = await this.ormRepository.update({
where: { id },
const group = await this.ormRepository.update({
where: { id },
data,
include: {
invited_users: {
select: {
email: true,
name: true,
}
},
},
invited_emails: {
select: {
email: true,
}
},
},
users: {
select: {
email: true,
name: true,
}
},
},
adms: {
select: {
email: true,
name: true,
}
},
},
},
});

return group;
}

}
2 changes: 0 additions & 2 deletions src/modules/groups/repositories/IGroupsRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import ICreateGroupDTO from '../dtos/ICreateGroupDTO';
import IUpdateGroupDTO from '../dtos/IUpdateGroupDTO';

interface IGroupsRepository {
// findByEmailWithRelations(email: string): Promise<Groups | null>;
// findByEmailPhoneOrCpf(email: string, phone: string, cpf: string): Promise<Groups | null>;
create(data: ICreateGroupDTO): Promise<Groups>;
findAll(): Promise<Groups[]>;
findById(id: string): Promise<Groups | null>;
Expand Down
Loading

0 comments on commit b70b4f5

Please sign in to comment.