Skip to content

Commit 54749f0

Browse files
authored
Merge pull request #87 from coder-mind-project/develop
Version 1.1.2-alpha
2 parents 5083506 + 0f03448 commit 54749f0

File tree

15 files changed

+209
-149
lines changed

15 files changed

+209
-149
lines changed

api/articles/comments/comments.js

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ module.exports = app => {
119119
{
120120
$lookup: {
121121
from: 'users',
122-
localField: 'article.author',
122+
localField: 'article.userId',
123123
foreignField: '_id',
124124
as: 'article.author'
125125
}
@@ -199,7 +199,7 @@ module.exports = app => {
199199
{
200200
$lookup: {
201201
from: 'users',
202-
localField: 'article.author',
202+
localField: 'article.userId',
203203
foreignField: '_id',
204204
as: 'article.author'
205205
}
@@ -220,10 +220,10 @@ module.exports = app => {
220220
article: {
221221
_id: 1,
222222
title: 1,
223-
customURL: 1,
224-
smallImg: 1,
225-
mediumImg: 1,
226-
largeImg: 1,
223+
customUri: 1,
224+
logoImg: 1,
225+
secondaryImg: 1,
226+
headerImg: 1,
227227
author: { $arrayElemAt: ['$article.author', 0] }
228228
}
229229
}
@@ -245,16 +245,16 @@ module.exports = app => {
245245
article: {
246246
_id: 1,
247247
title: 1,
248-
customURL: 1,
249-
smallImg: 1,
250-
mediumImg: 1,
251-
largeImg: 1,
248+
customUri: 1,
249+
logoImg: 1,
250+
secondaryImg: 1,
251+
headerImg: 1,
252252
author: {
253253
_id: 1,
254254
name: 1,
255255
tagAdmin: 1,
256256
tagAuthor: 1,
257-
customUrl: 1,
257+
customUri: 1,
258258
profilePhoto: 1
259259
}
260260
}
@@ -328,7 +328,7 @@ module.exports = app => {
328328
{
329329
$lookup: {
330330
from: 'users',
331-
localField: 'article.author',
331+
localField: 'article.userId',
332332
foreignField: '_id',
333333
as: 'article.author'
334334
}
@@ -408,7 +408,7 @@ module.exports = app => {
408408
{
409409
$lookup: {
410410
from: 'users',
411-
localField: 'article.author',
411+
localField: 'article.userId',
412412
foreignField: '_id',
413413
as: 'article.author'
414414
}
@@ -429,10 +429,10 @@ module.exports = app => {
429429
article: {
430430
_id: 1,
431431
title: 1,
432-
customURL: 1,
433-
smallImg: 1,
434-
mediumImg: 1,
435-
largeImg: 1,
432+
customUri: 1,
433+
logoImg: 1,
434+
secondaryImg: 1,
435+
headerImg: 1,
436436
author: { $arrayElemAt: ['$article.author', 0] }
437437
}
438438
}
@@ -454,16 +454,16 @@ module.exports = app => {
454454
article: {
455455
_id: 1,
456456
title: 1,
457-
customURL: 1,
458-
smallImg: 1,
459-
mediumImg: 1,
460-
largeImg: 1,
457+
customUri: 1,
458+
logoImg: 1,
459+
secondaryImg: 1,
460+
headerImg: 1,
461461
author: {
462462
_id: 1,
463463
name: 1,
464464
tagAdmin: 1,
465465
tagAuthor: 1,
466-
customUrl: 1,
466+
customUri: 1,
467467
profilePhoto: 1
468468
}
469469
}
@@ -536,7 +536,7 @@ module.exports = app => {
536536
{
537537
$lookup: {
538538
from: 'users',
539-
localField: 'article.author',
539+
localField: 'article.userId',
540540
foreignField: '_id',
541541
as: 'article.author'
542542
}
@@ -614,7 +614,7 @@ module.exports = app => {
614614
{
615615
$lookup: {
616616
from: 'users',
617-
localField: 'article.author',
617+
localField: 'article.userId',
618618
foreignField: '_id',
619619
as: 'article.author'
620620
}
@@ -635,10 +635,10 @@ module.exports = app => {
635635
article: {
636636
_id: 1,
637637
title: 1,
638-
customURL: 1,
639-
smallImg: 1,
640-
mediumImg: 1,
641-
largeImg: 1,
638+
customUri: 1,
639+
logoImg: 1,
640+
secondaryImg: 1,
641+
headerImg: 1,
642642
author: { $arrayElemAt: ['$article.author', 0] }
643643
}
644644
}
@@ -660,16 +660,16 @@ module.exports = app => {
660660
article: {
661661
_id: 1,
662662
title: 1,
663-
customURL: 1,
664-
smallImg: 1,
665-
mediumImg: 1,
666-
largeImg: 1,
663+
customUri: 1,
664+
logoImg: 1,
665+
secondaryImg: 1,
666+
headerImg: 1,
667667
author: {
668668
_id: 1,
669669
name: 1,
670670
tagAdmin: 1,
671671
tagAuthor: 1,
672-
customUrl: 1,
672+
customUri: 1,
673673
profilePhoto: 1
674674
}
675675
}
@@ -742,7 +742,7 @@ module.exports = app => {
742742
{
743743
$lookup: {
744744
from: 'users',
745-
localField: 'article.author',
745+
localField: 'article.userId',
746746
foreignField: '_id',
747747
as: 'article.author'
748748
}
@@ -821,7 +821,7 @@ module.exports = app => {
821821
{
822822
$lookup: {
823823
from: 'users',
824-
localField: 'article.author',
824+
localField: 'article.userId',
825825
foreignField: '_id',
826826
as: 'article.author'
827827
}
@@ -842,10 +842,10 @@ module.exports = app => {
842842
article: {
843843
_id: 1,
844844
title: 1,
845-
customURL: 1,
846-
smallImg: 1,
847-
mediumImg: 1,
848-
largeImg: 1,
845+
customUri: 1,
846+
logoImg: 1,
847+
secondaryImg: 1,
848+
headerImg: 1,
849849
author: { $arrayElemAt: ['$article.author', 0] }
850850
}
851851
}
@@ -867,16 +867,16 @@ module.exports = app => {
867867
article: {
868868
_id: 1,
869869
title: 1,
870-
customURL: 1,
871-
smallImg: 1,
872-
mediumImg: 1,
873-
largeImg: 1,
870+
customUri: 1,
871+
logoImg: 1,
872+
secondaryImg: 1,
873+
headerImg: 1,
874874
author: {
875875
_id: 1,
876876
name: 1,
877877
tagAdmin: 1,
878878
tagAuthor: 1,
879-
customUrl: 1,
879+
customUri: 1,
880880
profilePhoto: 1
881881
}
882882
}
@@ -966,7 +966,7 @@ module.exports = app => {
966966
{
967967
$lookup: {
968968
from: 'users',
969-
localField: 'article.author',
969+
localField: 'article.userId',
970970
foreignField: '_id',
971971
as: 'article.author'
972972
}
@@ -987,7 +987,7 @@ module.exports = app => {
987987
article: {
988988
_id: 1,
989989
title: 1,
990-
customURL: 1,
990+
customUri: 1,
991991
author: { $arrayElemAt: ['$article.author', 0] }
992992
}
993993
}
@@ -1008,13 +1008,13 @@ module.exports = app => {
10081008
article: {
10091009
_id: 1,
10101010
title: 1,
1011-
customURL: 1,
1011+
customUri: 1,
10121012
author: {
10131013
_id: 1,
10141014
name: 1,
10151015
tagAdmin: 1,
10161016
tagAuthor: 1,
1017-
customUrl: 1,
1017+
customUri: 1,
10181018
profilePhoto: 1
10191019
}
10201020
}
@@ -1053,13 +1053,13 @@ module.exports = app => {
10531053
article: {
10541054
_id: 1,
10551055
title: 1,
1056-
customURL: 1,
1056+
customUri: 1,
10571057
author: {
10581058
_id: 1,
10591059
name: 1,
10601060
tagAdmin: 1,
10611061
tagAuthor: 1,
1062-
customUrl: 1,
1062+
customUri: 1,
10631063
profilePhoto: 1
10641064
}
10651065
},

api/auth/auth.js

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,7 @@ module.exports = app => {
5353
description: 'É necessário informar uma senha'
5454
})
5555

56-
const countUsers = await User.countDocuments({ deletedAt: null })
57-
58-
// prettier-ignore
59-
const user = countUsers
60-
? await User.findOne({ email: request.email })
61-
: await app.knex
62-
.select()
63-
.from('users')
64-
.where('username', request.email)
65-
.orWhere('email', request.email)
66-
.first()
56+
const user = await User.findOne({ email: request.email })
6757

6858
if (!user) {
6959
throw {
@@ -83,7 +73,7 @@ module.exports = app => {
8373
const password = await encryptAuth(request.password)
8474

8575
if (user.password === password) {
86-
if (!user.firstLoginAt && countUsers) {
76+
if (!user.firstLoginAt) {
8777
const today = new Date()
8878
const result = await User.updateOne({ _id: user._id }, { firstLoginAt: today })
8979
if (result.nModified) user.firstLoginAt = today
@@ -154,18 +144,9 @@ module.exports = app => {
154144
}
155145
}
156146

157-
const origin = isNaN(payload.user._id)
147+
let user = await User.findOne({ _id: payload.user._id, deletedAt: null })
158148

159-
// prettier-ignore
160-
let user = origin
161-
? await User.findOne({ _id: payload.user._id, deletedAt: null })
162-
: await app.knex
163-
.select()
164-
.from('users')
165-
.where('id', payload.user._id)
166-
.first()
167-
168-
if (user && (user._id || user.id)) {
149+
if (user && user._id) {
169150
if (payload.user.email !== user.email) {
170151
throw {
171152
name: 'changedEmail',
@@ -178,11 +159,6 @@ module.exports = app => {
178159
token = jwt.encode(payload, secret)
179160
}
180161

181-
if (!origin) {
182-
user._id = user.id
183-
delete user.id
184-
}
185-
186162
user = user.toObject({
187163
transform: (doc, ret) => {
188164
delete ret.password

api/responses.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,8 @@ module.exports = app => {
191191
break
192192
}
193193
case 'Sua conta esta suspensa, em caso de reinvidicação entre em contato com o administrador do sistema':
194-
case 'E-mail ou senha inválidos': {
194+
case 'E-mail ou senha inválidos':
195+
case 'Acesso não autorizado': {
195196
reformulatedError.code = 401
196197
break
197198
}
@@ -382,13 +383,8 @@ module.exports = app => {
382383
pending = 'customUrl'
383384
reformulatedError.msg = 'Esta url personalizada já está cadastrada'
384385
} else {
385-
if (errors.cellphone && errors.cellphone.kind === 'unique') {
386-
pending = 'cellphone'
387-
reformulatedError.msg = 'Este número de telefone já esta associado a uma outra conta, tente outro número'
388-
} else {
389-
pending = 'MongoDB'
390-
reformulatedError.msg = 'Existe alguma restrição não mapeada, por favor reporte este problema'
391-
}
386+
pending = 'MongoDB'
387+
reformulatedError.msg = 'Existe alguma restrição não mapeada, por favor reporte este problema'
392388
}
393389
}
394390

@@ -417,6 +413,7 @@ module.exports = app => {
417413
case 'É necessário informar um genero':
418414
case "Tipo de usuário inválido, escolha entre 'author' e 'admin'":
419415
case 'Tipo de usuário inválido':
416+
case 'Este número de telefone já esta cadastrado':
420417
case 'Número de celular inválido':
421418
case 'Número de telefone inválido':
422419
case 'Ja existe cadastro com essas informações':

0 commit comments

Comments
 (0)