Skip to content

Commit cdee640

Browse files
committed
Continuando a implemento, erro na listagem de leads
1 parent 9cb893d commit cdee640

File tree

12 files changed

+115
-7
lines changed

12 files changed

+115
-7
lines changed

.idea/.gitignore

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/inspectionProfiles/Project_Default.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/sistema-email-nodejs-vuejs.iml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/src/components/email/email-edit.vue

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727
<input type="text" id="campanhaStart" v-model="email.start" />
2828
<label for="campanhaStart">Data de inicio</label>
2929
</div>
30+
<div class="input-filter">
31+
<select multiple class="browser-default" v-model="email.lists">
32+
<option v-for="list in lists" :value="list._id">{{list.title}}</option>
33+
</select>
34+
</div>
3035
<input type="submit" value="Salvar" class="btn" />
3136
</form>
3237
</div>
@@ -38,7 +43,12 @@
3843
export default {
3944
computed: {
4045
email: function () {
41-
return this.$store.state.email.email
46+
let email = this.$store.state.email.email
47+
email.lists = email.lists || []
48+
return email
49+
},
50+
lists: function () {
51+
return this.$store.state.list.lists
4252
}
4353
},
4454
methods: {
@@ -50,6 +60,7 @@ export default {
5060
},
5161
mounted () {
5262
this.$store.dispatch('getOne', this.$route.params.id)
63+
this.$store.dispatch('getAllList')
5364
}
5465
}
5566
</script>

client/src/components/email/email-new.vue

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
<input type="text" id="campanhaStart" v-model="data.start" />
2525
<label for="campanhaStart">Data de inicio</label>
2626
</div>
27+
<div class="input-filter">
28+
<select multiple class="browser-default" v-model="data.lists">
29+
<option v-for="list in lists" :value="list._id">{{list.title}}</option>
30+
</select>
31+
</div>
2732
<input type="submit" value="Salvar" class="btn" />
2833
</form>
2934
</div>
@@ -35,7 +40,14 @@
3540
export default {
3641
data: function () {
3742
return {
38-
data: {}
43+
data: {
44+
lists: []
45+
}
46+
}
47+
},
48+
computed: {
49+
lists: function () {
50+
return this.$store.state.list.lists
3951
}
4052
},
4153
methods: {
@@ -44,6 +56,9 @@ export default {
4456
this.$router.push('/email')
4557
})
4658
}
59+
},
60+
mounted () {
61+
this.$store.dispatch('getAllList')
4762
}
4863
}
4964
</script>

server/src/controllers/campaigns.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,27 @@ const service = new CrudService(model);
77
module.exports = function() {
88
const controller = new GenericController(model);
99

10+
controller.edit = (req, res) => {
11+
let data = req.body;
12+
data.lists = [];
13+
14+
Object.keys(req.body).forEach(function(element, index) {
15+
if(element.startsWith('lists[')){
16+
data.lists.push(req.body[element]);
17+
}else{
18+
data[element] = req.body[element]
19+
}
20+
});
21+
22+
service
23+
.update(req.params.id, data)
24+
.then(result => {
25+
return res.json(result);
26+
})
27+
.catch(err => {
28+
return res.status(422).json(err);
29+
});
30+
};
31+
1032
return controller;
1133
};

server/src/controllers/leads.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ module.exports = function() {
2020
check("list", "List is required").exists();
2121

2222
errors = validationResult(req);
23-
24-
if (errors) {
25-
return res.status(422).json(errors);
23+
24+
if (!errors.isEmpty()) {
25+
return res.status(422).json({ errors: errors.array() });
2626
}
2727

2828
let list;
@@ -80,8 +80,11 @@ module.exports = function() {
8080
};
8181

8282
controller.leadsByList = function(res, req) {
83+
console.log('leadsByList',req.params.id);
84+
let lists = req.params.id.split(',');
85+
8386
model
84-
.find({ lists: { $in: [req.params.id] } })
87+
.find({ lists: { $in: [lists] } })
8588
.populate("lists")
8689
.exec(function(err, leads) {
8790
return res.json({ data: leads });

0 commit comments

Comments
 (0)