Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Server
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
web-et-numerique
Factory
Resin
Server
Commits
fd5ebaf2
Commit
fd5ebaf2
authored
3 years ago
by
Hugo SUBTIL
Committed by
Antonin COQUET
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Feat/update data
parent
66ae0e8a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!96
release V1.10.0
,
!73
Dev
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/migrations/scripts/1618322296327-clean-data.ts
+103
-0
103 additions, 0 deletions
src/migrations/scripts/1618322296327-clean-data.ts
src/structures/schemas/time.schema.ts
+2
-2
2 additions, 2 deletions
src/structures/schemas/time.schema.ts
with
105 additions
and
2 deletions
src/migrations/scripts/1618322296327-clean-data.ts
0 → 100644
+
103
−
0
View file @
fd5ebaf2
import
{
Db
}
from
'
mongodb
'
;
import
{
getDb
}
from
'
../migrations-utils/db
'
;
export
const
up
=
async
()
=>
{
const
db
:
Db
=
await
getDb
();
const
cursor
=
db
.
collection
(
'
structures
'
).
find
({});
let
document
;
while
((
document
=
await
cursor
.
next
()))
{
const
newDoc
=
updateStructure
(
document
);
await
db
.
collection
(
'
structures
'
).
updateOne
({
_id
:
document
.
_id
},
[{
$set
:
newDoc
}]);
}
console
.
log
(
`Update done`
);
};
export
const
down
=
async
()
=>
{
const
db
:
Db
=
await
getDb
();
const
cursor
=
db
.
collection
(
'
structures
'
).
find
({});
let
document
;
while
((
document
=
await
cursor
.
next
()))
{
const
newDoc
=
downgradeStructure
(
document
);
await
db
.
collection
(
'
structures
'
).
updateOne
({
_id
:
document
.
_id
},
[{
$set
:
newDoc
}]);
}
console
.
log
(
`Update done`
);
};
function
updateStructure
(
doc
)
{
doc
=
updateHours
(
doc
);
doc
=
removeUnusedFields
(
doc
);
return
doc
;
}
function
downgradeStructure
(
doc
)
{
doc
=
restoreHours
(
doc
);
return
doc
;
}
function
updateHours
(
doc
)
{
if
(
doc
.
hours
)
{
Object
.
keys
(
doc
.
hours
).
forEach
((
key
)
=>
{
if
(
doc
.
hours
[
key
].
time
.
length
>
0
)
{
doc
.
hours
[
key
].
time
.
forEach
((
timeRange
)
=>
{
timeRange
.
openning
=
formatHours
(
timeRange
.
openning
);
timeRange
.
closing
=
formatHours
(
timeRange
.
closing
);
});
}
});
return
doc
;
}
else
{
console
.
warn
(
`No hours on doc
${
doc
.
_id
}
`
);
return
doc
;
}
}
function
restoreHours
(
doc
)
{
if
(
doc
.
hours
)
{
Object
.
keys
(
doc
.
hours
).
forEach
((
key
)
=>
{
if
(
doc
.
hours
[
key
].
time
.
length
>
0
)
{
doc
.
hours
[
key
].
time
.
forEach
((
timeRange
)
=>
{
timeRange
.
openning
=
formatBackHours
(
timeRange
.
openning
);
timeRange
.
closing
=
formatBackHours
(
timeRange
.
closing
);
});
}
});
return
doc
;
}
else
{
console
.
warn
(
`No hours on doc
${
doc
.
_id
}
`
);
return
doc
;
}
}
function
formatHours
(
hour
):
string
{
const
stringifiedHour
=
hour
.
toString
();
if
(
stringifiedHour
.
length
===
3
)
{
// 930
return
stringifiedHour
.
slice
(
0
,
1
)
+
'
:
'
+
stringifiedHour
.
slice
(
1
,
3
);
}
else
if
(
stringifiedHour
.
length
===
4
)
{
// 1200
return
stringifiedHour
.
slice
(
0
,
2
)
+
'
:
'
+
stringifiedHour
.
slice
(
2
,
4
);
}
}
function
formatBackHours
(
hour
):
number
{
const
splitedHour
=
hour
.
split
(
'
:
'
);
return
parseInt
(
''
.
concat
(...
splitedHour
),
10
);
}
function
removeUnusedFields
(
doc
)
{
if
(
doc
[
'
equipmentDetails
'
])
{
delete
doc
[
'
equipmentDetails
'
];
}
if
(
doc
[
'
nomDeLusager
'
])
{
delete
doc
[
'
nomDeLusager
'
];
}
if
(
doc
[
'
statutJuridique
'
])
{
delete
doc
[
'
statutJuridique
'
];
}
if
(
doc
[
'
documentsMeeting
'
])
{
delete
doc
[
'
documentsMeeting
'
];
}
return
doc
;
}
This diff is collapsed.
Click to expand it.
src/structures/schemas/time.schema.ts
+
2
−
2
View file @
fd5ebaf2
...
...
@@ -4,8 +4,8 @@ import { Document } from 'mongoose';
export
type
TimeDocument
=
Time
&
Document
;
export
class
Time
{
openning
:
number
;
closing
:
number
;
openning
:
string
;
closing
:
string
;
}
export
const
TimeSchema
=
SchemaFactory
.
createForClass
(
Time
);
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment