Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/subscription #8

Merged
merged 5 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 @@

const {
name,
description,

Check failure on line 57 in src/modules/groups/infra/http/controller/GroupsController.ts

View workflow job for this annotation

GitHub Actions / Check linting (20.11.1)

'description' is assigned a value but never used
} = 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 @@
}

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 }

Check failure on line 21 in src/modules/groups/infra/prisma/repositories/GroupsRepository.ts

View workflow job for this annotation

GitHub Actions / Check linting (20.11.1)

Missing trailing comma
},
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 @@
}

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 @@
}

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
Loading