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

refactor: Refatoração da rota de campaign #292

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
75 changes: 75 additions & 0 deletions dist/routes/csv.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,40 @@
'use strict';
var __awaiter =
(this && this.__awaiter) ||
function (thisArg, _arguments, P, generator) {
function adopt(value) {
return value instanceof P
? value
: new P(function (resolve) {
resolve(value);
});
}
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
}
function rejected(value) {
try {
step(generator['throw'](value));
} catch (e) {
reject(e);
}
}
function step(result) {
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
}
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, '__esModule', { value: true });
const FileDAO_1 = require('../models/DAO/FileDAO');
const DateUtils_1 = require('../utils/DateUtils');
const ApiResponse_1 = require('../models/ApiResponse');
const CampaignDAO_1 = require('../models/DAO/CampaignDAO');
const csv = (app) => {
app.post('/csv', (req, res) => {
const campaign = req.headers.campaign;
Expand Down Expand Up @@ -81,6 +113,49 @@ const csv = (app) => {
}
});
});
app.get('/:adOpsTeam/:campaignId/csv/list', (req, res) =>
__awaiter(void 0, void 0, void 0, function* () {
const apiResponse = new ApiResponse_1.ApiResponse();
const campaignId = req.params.campaignId;
const adOpsTeam = req.params.adOpsTeam;
const adOpsTeamPath = adOpsTeam === 'Campanhas Internas' ? 'AdvertiserCampaigns' : adOpsTeam;
const advertiser = req.advertiser;
const permission = req.permission;
const campaignObject = new CampaignDAO_1.CampaignDAO();
const campaign = yield campaignObject.getCampaign(campaignId);
const fileDAO = new FileDAO_1.FileDAO();
if (
(permission === 'adOpsManager' || permission === 'user') &&
(!adOpsTeam || adOpsTeam === 'Campanhas Internas')
) {
apiResponse.responseText = 'Nenhuma adOpsTeam foi informada!';
apiResponse.statusCode = 400;
res.status(apiResponse.statusCode).send(apiResponse.jsonResponse);
return;
} else if (!campaign) {
apiResponse.responseText = 'Nenhuma campanha foi informada!';
apiResponse.statusCode = 400;
res.status(apiResponse.statusCode).send(apiResponse.jsonResponse);
return;
}
const filePath = `${advertiser}/${adOpsTeamPath}/${campaign}/`;
fileDAO
.getAllFilesFromStore(filePath)
.then((data) => {
const files = data[0].filter((file) => /\.csv$/.test(file.name)).map((file) => file.name);
apiResponse.responseText = files.join(',');
apiResponse.statusCode = 200;
})
.catch((err) => {
apiResponse.errorMessage = err.message;
apiResponse.responseText = `Falha ao restaurar os arquivos!`;
apiResponse.statusCode = 500;
})
.finally(() => {
res.status(apiResponse.statusCode).send(apiResponse.jsonResponse);
});
})
);
app.get('/csv/list', (req, res) => {
const getAllAdOpsTeamsFrom = req.getAllAdOpsTeamsFrom;
const advertiser = req.advertiser;
Expand Down
68 changes: 0 additions & 68 deletions src/ts/routes/campaign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,74 +52,6 @@ const campaign = (app: { [key: string]: any }): void => {
});
});

app.get('/campaign/:adOpsTeam/list', async (req: { [key: string]: any }, res: { [key: string]: any }) => {
WernerAssis marked this conversation as resolved.
Show resolved Hide resolved
const apiResponse = new ApiResponse();

const adOpsTeam = req.params.adOpsTeam !== 'Campanhas Internas' ? req.params.adOpsTeam : 'AdvertiserCampaigns';
const permission = req.permission;

new CampaignDAO()
.getAllCampaignsFrom(adOpsTeam, permission)
.then((adOpsTeams: { campaignName: string; campaignId: string }[]) => {
apiResponse.responseText = JSON.stringify(adOpsTeams);
})
.catch((err) => {
apiResponse.statusCode = 500;
apiResponse.responseText = err.message;
apiResponse.errorMessage = err.message;
})
.finally(() => {
res.status(apiResponse.statusCode).send(apiResponse.jsonResponse);
});
});

app.get('/:adOpsTeam/:campaignId/csv/list', async (req: { [key: string]: any }, res: { [key: string]: any }) => {
const apiResponse = new ApiResponse();
const campaignId = req.params.campaignId;

const adOpsTeam = req.params.adOpsTeam;
const adOpsTeamPath = adOpsTeam === 'Campanhas Internas' ? 'AdvertiserCampaigns' : adOpsTeam;
const advertiser = req.advertiser;
const permission = req.permission;
const campaignObject = new CampaignDAO();
const campaign = await campaignObject.getCampaign(campaignId);
const fileDAO = new FileDAO();

// uma evolucao aqui eh o owner/admin conseguir ver (e selecionar) as campanhas de todas as agencias
if (
(permission === 'adOpsManager' || permission === 'user') &&
(!adOpsTeam || adOpsTeam === 'Campanhas Internas')
) {
apiResponse.responseText = 'Nenhuma adOpsTeam foi informada!';
apiResponse.statusCode = 400;
res.status(apiResponse.statusCode).send(apiResponse.jsonResponse);
return;
} else if (!campaign) {
apiResponse.responseText = 'Nenhuma campanha foi informada!';
apiResponse.statusCode = 400;
res.status(apiResponse.statusCode).send(apiResponse.jsonResponse);
return;
}

const filePath = `${advertiser}/${adOpsTeamPath}/${campaign}/`;

fileDAO
.getAllFilesFromStore(filePath)
.then((data) => {
const files = data[0].filter((file) => /\.csv$/.test(file.name)).map((file) => file.name);
apiResponse.responseText = files.join(',');
apiResponse.statusCode = 200;
})
.catch((err) => {
apiResponse.errorMessage = err.message;
apiResponse.responseText = `Falha ao restaurar os arquivos!`;
apiResponse.statusCode = 500;
})
.finally(() => {
res.status(apiResponse.statusCode).send(apiResponse.jsonResponse);
});
});

app.post('/campaign/:id/deactivate', async (req: { [key: string]: any }, res: { [key: string]: any }) => {
const apiResponse = new ApiResponse();
const campaignId = req.params.id;
Expand Down
48 changes: 48 additions & 0 deletions src/ts/routes/csv.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { FileDAO } from '../models/DAO/FileDAO';
import { DateUtils } from '../utils/DateUtils';
import { ApiResponse } from '../models/ApiResponse';
import { CampaignDAO } from '../models/DAO/CampaignDAO';

const csv = (app: { [key: string]: any }): void => {
app.post('/csv', (req: { [key: string]: any }, res: { [key: string]: any }) => {
Expand Down Expand Up @@ -90,6 +91,53 @@ const csv = (app: { [key: string]: any }): void => {
});
});

app.get('/:adOpsTeam/:campaignId/csv/list', async (req: { [key: string]: any }, res: { [key: string]: any }) => {
const apiResponse = new ApiResponse();
const campaignId = req.params.campaignId;

const adOpsTeam = req.params.adOpsTeam;
const adOpsTeamPath = adOpsTeam === 'Campanhas Internas' ? 'AdvertiserCampaigns' : adOpsTeam;
const advertiser = req.advertiser;
const permission = req.permission;
const campaignObject = new CampaignDAO();
const campaign = await campaignObject.getCampaign(campaignId);
const fileDAO = new FileDAO();

// uma evolucao aqui eh o owner/admin conseguir ver (e selecionar) as campanhas de todas as agencias
if (
(permission === 'adOpsManager' || permission === 'user') &&
(!adOpsTeam || adOpsTeam === 'Campanhas Internas')
) {
apiResponse.responseText = 'Nenhuma adOpsTeam foi informada!';
apiResponse.statusCode = 400;
res.status(apiResponse.statusCode).send(apiResponse.jsonResponse);
return;
} else if (!campaign) {
apiResponse.responseText = 'Nenhuma campanha foi informada!';
apiResponse.statusCode = 400;
res.status(apiResponse.statusCode).send(apiResponse.jsonResponse);
return;
}

const filePath = `${advertiser}/${adOpsTeamPath}/${campaign}/`;

fileDAO
.getAllFilesFromStore(filePath)
.then((data) => {
const files = data[0].filter((file) => /\.csv$/.test(file.name)).map((file) => file.name);
apiResponse.responseText = files.join(',');
apiResponse.statusCode = 200;
})
.catch((err) => {
apiResponse.errorMessage = err.message;
apiResponse.responseText = `Falha ao restaurar os arquivos!`;
apiResponse.statusCode = 500;
})
.finally(() => {
res.status(apiResponse.statusCode).send(apiResponse.jsonResponse);
});
});

app.get('/csv/list', (req: { [key: string]: any }, res: { [key: string]: any }) => {
const getAllAdOpsTeamsFrom = req.getAllAdOpsTeamsFrom;
const advertiser = req.advertiser;
Expand Down