Skip to content

Commit

Permalink
Merge pull request #119 from DP6/refactor_cleanup
Browse files Browse the repository at this point in the history
refactor: ♻️ cleaning variables, functions and typing
  • Loading branch information
LucasTonetto authored Nov 9, 2021
2 parents 993eb90 + 5ab52cb commit ad4ecb1
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 17 deletions.
3 changes: 1 addition & 2 deletions dist/models/DAO/AgencyDAO.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ class AgencyDAO {
constructor() {
this._objectStore = FirestoreConnectionSingleton_1.FirestoreConnectionSingleton.getInstance();
this._pathToCollection = ['tokens'];
this._authCollection = this._objectStore.getCollection(this._pathToCollection);
}
getAllAgenciesFrom(company, agency, userRequestPermission) {
return this._objectStore
Expand Down Expand Up @@ -38,7 +37,7 @@ class AgencyDAO {
throw err;
});
}
getAllUsersFromAgency(company, agency, userRequestPermission) {
getAllUsersFromAgency(company, agency) {
return this._objectStore
.getCollection(this._pathToCollection)
.where('company', '==', company)
Expand Down
5 changes: 3 additions & 2 deletions dist/models/DAO/CampaignDAO.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ class CampaignDAO {
if (
campaignInfos.campaignName &&
campaignInfos.campaignId &&
campaignInfos.campaignId &&
campaignInfos.campaignId &&
campaignInfos.agency &&
campaignInfos.activate !== null &&
campaignInfos.activate !== undefined &&
!campaigns.includes(campaignInfos)
) {
campaigns.push(campaignInfos);
Expand Down
4 changes: 3 additions & 1 deletion dist/routes/agency.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ const agency = (app) => {
app.get('/agency/users', (req, res) =>
__awaiter(void 0, void 0, void 0, function* () {
const apiResponse = new ApiResponse_1.ApiResponse();
const company = req.company;
const agency = req.agency;
new AgencyDAO_1.AgencyDAO()
.getAllUsersFromAgency(req.company, req.agency, req.permission)
.getAllUsersFromAgency(company, agency)
.then((users) => {
apiResponse.responseText = JSON.stringify(users.map((user) => user.toJson()));
})
Expand Down
9 changes: 3 additions & 6 deletions src/ts/models/DAO/AgencyDAO.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import { FirestoreConnectionSingleton } from '../cloud/FirestoreConnectionSingleton';
import { CollectionReference, QuerySnapshot } from '@google-cloud/firestore';
import { QuerySnapshot } from '@google-cloud/firestore';
import { ObjectStore } from './ObjectStore';
import { User } from '../User';

export class AgencyDAO {
private _objectStore: ObjectStore;
private _pathToCollection: string[];
private _authCollection: CollectionReference;

constructor() {
this._objectStore = FirestoreConnectionSingleton.getInstance();
this._pathToCollection = ['tokens'];
this._authCollection = this._objectStore.getCollection(this._pathToCollection);
}

/**
Expand All @@ -21,7 +19,7 @@ export class AgencyDAO {
* @param userRequestPermission permissão do usuario que solicitou a alteração
* @returns Lista de agências
*/
public getAllAgenciesFrom(company: string, agency: string, userRequestPermission: string): Promise<string[] | void> {
public getAllAgenciesFrom(company: string, agency: string, userRequestPermission: string): Promise<string[]> {
return this._objectStore
.getCollection(['tokens'])
.where('company', '==', company)
Expand Down Expand Up @@ -55,10 +53,9 @@ export class AgencyDAO {
* Retorna todos os usuários de uma determinada agência
* @param company Empresa(company) dos usuários a serem buscados
* @param agency Agência da qual usuários serão buscados
* @param userRequestPermission permissão do usuario que solicitou a alteração
* @returns Lista de usuários
*/
public getAllUsersFromAgency(company: string, agency: string, userRequestPermission: string): Promise<User[] | void> {
public getAllUsersFromAgency(company: string, agency: string): Promise<User[] | void> {
return this._objectStore
.getCollection(this._pathToCollection)
.where('company', '==', company)
Expand Down
7 changes: 4 additions & 3 deletions src/ts/models/DAO/CampaignDAO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class CampaignDAO {
public getAllCampaignsFrom(
agency: string,
userRequestPermission: string
): Promise<{ campaignName: string; campaignId: string }[]> {
): Promise<{ campaignName: string; campaignId: string; agency: string; activate: boolean }[]> {
return this._objectStore
.getCollection(this._pathToCollection)
.where('agency', '==', agency)
Expand All @@ -80,8 +80,9 @@ export class CampaignDAO {
if (
campaignInfos.campaignName &&
campaignInfos.campaignId &&
campaignInfos.campaignId &&
campaignInfos.campaignId &&
campaignInfos.agency &&
campaignInfos.activate !== null &&
campaignInfos.activate !== undefined &&
!campaigns.includes(campaignInfos)
) {
campaigns.push(campaignInfos);
Expand Down
5 changes: 4 additions & 1 deletion src/ts/routes/agency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ const agency = (app: { [key: string]: any }): void => {

app.get('/agency/users', async (req: { [key: string]: any }, res: { [key: string]: any }) => {
const apiResponse = new ApiResponse();
const company = req.company;
const agency = req.agency;

new AgencyDAO()
.getAllUsersFromAgency(req.company, req.agency, req.permission)
.getAllUsersFromAgency(company, agency)
.then((users: User[]) => {
apiResponse.responseText = JSON.stringify(users.map((user: User) => user.toJson()));
})
Expand Down
6 changes: 4 additions & 2 deletions src/ts/routes/campaign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,14 @@ const campaign = (app: { [key: string]: any }): void => {
return await new AgencyDAO().getAllAgenciesFrom(company, agency, permission);
};

const allAgencies: any = await gettingAgencies();
const allAgencies: string[] = await gettingAgencies();
if (permission === 'owner' || permission === 'admin') {
allAgencies.push('CompanyCampaigns');
}
if (permission === 'admin' || permission === ' owner') allAgencies.push('Campanhas Internas');
const agenciesToReturn: any = [];
const agenciesToReturn: {
[key: string]: { campaignName: string; campaignId: string; agency: string; activate: boolean }[];
}[] = [];
for await (const agencyInfos of allAgencies) {
try {
const campaignsObject = await new CampaignDAO().getAllCampaignsFrom(agencyInfos, permission);
Expand Down

0 comments on commit ad4ecb1

Please sign in to comment.