Skip to content

Commit

Permalink
fix(structures): Current name can to be in the future /5
Browse files Browse the repository at this point in the history
  • Loading branch information
annelhote committed Dec 18, 2024
1 parent 5ff4084 commit bd55410
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions src/api/commons/queries/current-name.query.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,30 @@
export default [
{
$set: {
names: {
$map: {
input: '$names',
in: { $mergeObjects: ['$$this', { startDate: { $concat: ['$$this.startDate', '-01-01'] } }] },
},
},
},
},
{
$set: {
names: {
$map: {
input: '$names',
in: {
$cond: [
{ $ifNull: ['$$this.startDate', 0] },
{ $mergeObjects: ['$$this', { startDate: { $substr: ['$$this.startDate', 0, 10] } }] },
'$$this',
],
},
},
},
},
},
{
$set: {
filteredNames: {
Expand All @@ -15,11 +41,7 @@ export default [
$reduce: {
input: '$filteredNames',
initialValue: null,
in: {
$cond: [
{ $gt: ['$$this.startDate', '$$value.startDate'] }, '$$this', '$$value',
],
},
in: { $cond: [{ $gt: ['$$this.startDate', '$$value.startDate'] }, '$$this', '$$value'] },
},
},
},
Expand All @@ -31,11 +53,7 @@ export default [
$reduce: {
input: '$filteredNames',
initialValue: null,
in: {
$cond: [
{ $gt: ['$$this.createdAt', '$$value.createdAt'] }, '$$this', '$$value',
],
},
in: { $cond: [{ $gt: ['$$this.createdAt', '$$value.createdAt'] }, '$$this', '$$value'] },
},
}],
},
Expand Down

0 comments on commit bd55410

Please sign in to comment.