Skip to content

Commit

Permalink
feat: 🎨 primeira versão add campaign
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustavo Ueti committed Oct 5, 2021
1 parent 65e9af0 commit aa1e714
Show file tree
Hide file tree
Showing 10 changed files with 8,709 additions and 17 deletions.
Empty file added dist/models/DAO/CampaignDAO.js
Empty file.
89 changes: 89 additions & 0 deletions dist/routes/campaign.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
'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 ApiResponse_1 = require('../models/ApiResponse');
const FirestoreConnectionSingleton_1 = require('../models/cloud/FirestoreConnectionSingleton');
const FileDAO_1 = require('../models/DAO/FileDAO');
const firestore_1 = require('@google-cloud/firestore');
const campaign = (app) => {
app.get('/campaign/list', (req, res) =>
__awaiter(void 0, void 0, void 0, function* () {
console.log(
'#################################################### to vivo ####################################################'
);
const firestore = new firestore_1.Firestore();
const collection = firestore.collection('campaigns');
console.log(collection.doc());
const fileDAO = new FileDAO_1.FileDAO();
})
);
app.post('/campaign/add', (req, res) =>
__awaiter(void 0, void 0, void 0, function* () {
const apiResponse = new ApiResponse_1.ApiResponse();
const firestore = new firestore_1.Firestore();
const collection = firestore.collection('campaigns');
const firestoreConnectionInstance = FirestoreConnectionSingleton_1.FirestoreConnectionSingleton.getInstance();
const today = new Date();
const day = String(today.getDate()).padStart(2, '0');
const month = String(today.getMonth() + 1).padStart(2, '0');
const year = today.getFullYear();
const values = {
created: `${year}-${month}-${day}`,
company: req.company,
agency: req.agency,
activated: true,
};
new Promise((resolve, reject) => {
if (values) {
apiResponse.responseText = JSON.stringify(values);
apiResponse.statusCode = 200;
resolve('Campanha criada');
} else {
apiResponse.statusCode = 400;
apiResponse.responseText = JSON.stringify(values);
reject('Criação da campanha falhou!');
}
})
.then(() => {
firestoreConnectionInstance.addDocumentIn(collection, values, 'Campanha Teste');
})
.catch((message) => {
throw message;
})
.finally(() => {
res.status(apiResponse.statusCode).send(apiResponse.jsonResponse);
});
})
);
};
exports.default = campaign;
1 change: 1 addition & 0 deletions dist/routes/csv.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const csv = (app) => {
const agency = req.agency;
const campaign = req.headers.campaign;
const company = req.company;
console.log('agencia: ' + agency);
const apiResponse = new ApiResponse_1.ApiResponse();
if (!fileName) {
apiResponse.responseText = 'Nenhum arquivo foi informado!';
Expand Down
2 changes: 2 additions & 0 deletions dist/routes/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const build_1 = require('./build');
const register_1 = require('./register');
const user_1 = require('./user');
const login_1 = require('./login');
const campaign_1 = require('./campaign');
const routes = (app) => {
config_1.default(app);
csv_1.default(app);
Expand All @@ -15,5 +16,6 @@ const routes = (app) => {
register_1.default(app);
user_1.default(app);
login_1.default(app);
campaign_1.default(app);
};
exports.default = routes;
Loading

0 comments on commit aa1e714

Please sign in to comment.