Skip to content

Commit 9cb893d

Browse files
committed
Continuando a implementar!
1 parent 1fa3f53 commit 9cb893d

File tree

9 files changed

+205
-8
lines changed

9 files changed

+205
-8
lines changed

client/src/App.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
</a>
2222
</li>
2323
<li>
24-
<a href="/lists">
24+
<a href="#/lists">
2525
<i class="material-icons">supervisor_account</i>
2626
</a>
2727
</li>
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<template>
2+
<div class="row">
3+
<div class="col s12">
4+
<h5>{{lead.email}}</h5>
5+
</div>
6+
7+
<div class="col s6">
8+
<div class="card">
9+
<div class="card-content">
10+
<table>
11+
<thead>
12+
<tr>
13+
<th>#</th>
14+
<th>campo</th>
15+
<th>valor</th>
16+
<th></th>
17+
</tr>
18+
</thead>
19+
<tbody>
20+
<tr v-for="data in lead.data">
21+
<td>{{data.label}}</td>
22+
<td>{{data.value}}</td>
23+
<td>
24+
<a :href="'#/lists/' + list._id" class="btn">ver</a>
25+
</td>
26+
</tr>
27+
</tbody>
28+
</table>
29+
</div>
30+
</div>
31+
</div>
32+
33+
<div class="col s6">
34+
<div class="card">
35+
<div class="card-content">
36+
<span class="card-title">Listas ativas</span>
37+
<table>
38+
<thead>
39+
<tr>
40+
<th>#</th>
41+
<th>campo</th>
42+
<th>valor</th>
43+
<th></th>
44+
</tr>
45+
</thead>
46+
<tbody>
47+
<tr v-for="(list) in lead.lists">
48+
<td>{{list.label}}</td>
49+
<td>
50+
<a :href="'#/lists/' + list._id" class="btn">ver</a>
51+
</td>
52+
</tr>
53+
</tbody>
54+
</table>
55+
</div>
56+
</div>
57+
</div>
58+
</div>
59+
</template>
60+
<script>
61+
export default {
62+
computed: {
63+
lead: function () {
64+
return this.$store.state.lead.lead
65+
}
66+
},
67+
mounted: function () {
68+
this.$store.dispatch('getOneLead', this.$router.params.id)
69+
}
70+
}
71+
</script>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<template>
2+
<div class="row">
3+
<div class="col s12">
4+
<h5>Exibindo leads</h5>
5+
</div>
6+
<div class="col s12">
7+
<div class="card">
8+
<div class="card-content">
9+
<table>
10+
<thead>
11+
<tr>
12+
<th>#</th>
13+
<th>Emails</th>
14+
<th>Listas</th>
15+
<th></th>
16+
</tr>
17+
</thead>
18+
<tbody>
19+
<tr v-for="(lead, index) in leads">
20+
<td>{{ index }}</td>
21+
<td>{{ lead.email }}</td>
22+
<td>
23+
<div class="chip" v-for="chip in lead.lists">
24+
{{ chip.title }}
25+
</div>
26+
</td>
27+
<td>
28+
<a :href="'#/leads/' + lead._id" class="btn"></a>
29+
</td>
30+
</tr>
31+
</tbody>
32+
</table>
33+
</div>
34+
</div>
35+
</div>
36+
</div>
37+
</template>
38+
<script>
39+
export default {
40+
computed: {
41+
leads: function () {
42+
return this.$store.state.lead.leads
43+
}
44+
},
45+
mounted () {
46+
this.$store.dispatch('getAllLeads', this.$route.params.id)
47+
}
48+
}
49+
</script>

client/src/router/index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ import EmailNew from '@/components/email/email-new'
99
import EmailView from '@/components/email/email-view'
1010
import EmailEdit from '@/components/email/email-edit'
1111
import EmailRemove from '@/components/email/email-remove'
12+
1213
import ListsList from '@/components/lists/lists-list'
14+
import ListsView from '@/components/lists/lists-view'
15+
import ListsLead from '@/components/lists/lead'
1316

1417
Vue.use(Router)
1518

@@ -57,6 +60,18 @@ let router = new Router({
5760
component: ListsList,
5861
meta: {requiresAuth: true}
5962
},
63+
{
64+
path: '/lists/:id',
65+
name: 'ListsView',
66+
component: ListsView,
67+
meta: {requiresAuth: true}
68+
},
69+
{
70+
path: '/leads/:id',
71+
name: 'ListsLead',
72+
component: ListsLead,
73+
meta: {requiresAuth: true}
74+
},
6075
{
6176
path: '/login',
6277
name: 'Login',

client/src/states/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Vuex from 'vuex'
44
import user from './modules/user'
55
import email from './modules/email'
66
import list from './modules/list'
7+
import lead from './modules/lead'
78

89
window.axios = require('axios')
910
window.axios.defaults.baseURL = process.env.SERVER
@@ -13,7 +14,8 @@ let config = {
1314
modules: {
1415
user: user,
1516
email: email,
16-
list: list
17+
list: list,
18+
lead: lead
1719
}
1820
}
1921

client/src/states/modules/lead.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
export default {
3+
state: {
4+
leads: [],
5+
lead: {}
6+
},
7+
mutations: {
8+
updateLeads (state, data) {
9+
state.leads = data
10+
},
11+
updateLead (state, data) {
12+
state.lead = data
13+
}
14+
},
15+
actions: {
16+
getAllLeads (context, id) {
17+
return window.axios.get('/api/leads-by-list/' + id).then((response) => {
18+
context.commit('updateLeads', response.data.data)
19+
return response
20+
})
21+
},
22+
getOneLead (context, id) {
23+
return window.axios.get('/api/leads/' + id).then((response) => {
24+
context.commit('updateLead', response.data.data)
25+
return response
26+
})
27+
}
28+
}
29+
}

server/app.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const logger = require('morgan');
66
const mongoose = require('./src/db/connection');
77
const cors = require('cors');
88
const routes = require('./src/routes');
9-
const validator = require('express-validator');
9+
// const validator = require('express-validator');
1010

1111
// let indexRouter = require('./routes/index');
1212
// let usersRouter = require('./routes/users');
@@ -23,7 +23,7 @@ app.use(express.json());
2323
app.use(express.urlencoded({ extended: false }));
2424
app.use(cookieParser());
2525
app.use(express.static(path.join(__dirname, 'public')));
26-
app.use(validator());
26+
// app.use(validator());
2727

2828

2929
// app.use('/', indexRouter);

server/src/controllers/leads.js

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
const model = require("../models/lead");
22
const listModel = require("../models/list");
33
const GenericController = require("./generic");
4+
const { check, validationResult } = require("express-validator");
45

56
module.exports = function() {
67
const controller = new GenericController(model);
78

89
controller.subscribe = async function(req, res) {
9-
req.checkBody("email", "Enter a valid email").isEmail();
10-
req.checkBody("list", "List is required").exists();
10+
// req.checkBody("email", "Enter a valid email").isEmail();
11+
// req.checkBody("list", "List is required").exists();
1112

12-
let errors = req.validationErrors();
13+
// let errors = req.validationErrors();
14+
15+
// if (errors) {
16+
// return res.status(422).json(errors);
17+
// }
18+
19+
check("email", "Enter a valid email").isEmail();
20+
check("list", "List is required").exists();
21+
22+
errors = validationResult(req);
1323

1424
if (errors) {
1525
return res.status(422).json(errors);
@@ -64,11 +74,31 @@ module.exports = function() {
6474
}
6575
});
6676

67-
6877
return res.json({
6978
status: "success"
7079
});
7180
};
7281

82+
controller.leadsByList = function(res, req) {
83+
model
84+
.find({ lists: { $in: [req.params.id] } })
85+
.populate("lists")
86+
.exec(function(err, leads) {
87+
return res.json({ data: leads });
88+
});
89+
};
90+
91+
controller.view = function(req, res) {
92+
model
93+
.findById(req.params.id)
94+
.populate("lists")
95+
.exec((err, result) => {
96+
if (err) {
97+
return res.status(404).json(err);
98+
}
99+
return res.json({ data: result });
100+
});
101+
};
102+
73103
return controller;
74104
};

server/src/routes/leads.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module.exports = function(app) {
33

44
app.post("/leads/subscribe", controller.subscribe);
55

6+
app.get("/api/leads-by-list/:id", controller.leadsByList);
67
app.get("/api/leads", controller.index);
78
app.post("/api/leads", controller.add);
89
app.get("/api/leads/:id", controller.view);

0 commit comments

Comments
 (0)