-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into gfay_refacto_nest
- Loading branch information
Showing
12 changed files
with
89 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,4 +35,4 @@ lerna-debug.log* | |
!.vscode/extensions.json | ||
|
||
.env | ||
contours-communes.json | ||
contours-communes.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,41 +95,6 @@ test.serial('create a BaseLocale / invalid commune', async t => { | |
}) | ||
}) | ||
|
||
test.serial('get all BaseLocales', async t => { | ||
const _idBalA = new mongo.ObjectId() | ||
const _idBalB = new mongo.ObjectId() | ||
|
||
await mongo.db.collection('bases_locales').insertOne({ | ||
_id: _idBalA, | ||
nom: 'foo', | ||
emails: ['[email protected]'], | ||
commune: '27115', | ||
token: 'coucou', | ||
_created: new Date('2019-01-01'), | ||
_updated: new Date('2019-01-01'), | ||
_deleted: null | ||
}) | ||
|
||
await mongo.db.collection('bases_locales').insertOne({ | ||
_id: _idBalB, | ||
nom: 'fobaro', | ||
emails: ['[email protected]'], | ||
commune: '27115', | ||
token: 'hello', | ||
_created: new Date('2019-01-01'), | ||
_updated: new Date('2019-01-01'), | ||
_deleted: new Date('2020-01-01') | ||
}) | ||
|
||
const {body, status} = await request(getApp()) | ||
.get('/bases-locales') | ||
|
||
t.is(status, 200) | ||
t.is(body.length, 2) | ||
t.true(SAFE_FIELDS.every(k => k in body[0])) | ||
t.is(Object.keys(body[0]).length, SAFE_FIELDS.length) | ||
}) | ||
|
||
test.serial('get a BaseLocal / with admin token', async t => { | ||
const _id = new mongo.ObjectId() | ||
await mongo.db.collection('bases_locales').insertOne({ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const mongo = require('../util/mongo') | ||
|
||
async function getMongoCache(name) { | ||
const cache = await mongo.db.collection('_mongo-cache').findOne({name}) | ||
|
||
return cache?.value | ||
} | ||
|
||
function setMongoCache(name, value) { | ||
return mongo.db.collection('_mongo-cache').updateOne( | ||
{name}, | ||
{$set: {value}}, | ||
{upsert: true} | ||
) | ||
} | ||
|
||
module.exports = {getMongoCache, setMongoCache} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
class TaskQueue { | ||
constructor() { | ||
this.queue = [] | ||
this.isTaskRunning = false | ||
} | ||
|
||
pushTask(task) { | ||
this.queue.push(task) | ||
if (!this.isTaskRunning) { | ||
this.runTaskQueue() | ||
} | ||
} | ||
|
||
async runTaskQueue() { | ||
this.isTaskRunning = true | ||
|
||
while (this.queue.length > 0) { | ||
const task = this.queue.shift() | ||
// eslint-disable-next-line no-await-in-loop | ||
await task() | ||
} | ||
|
||
this.isTaskRunning = false | ||
} | ||
} | ||
|
||
module.exports = {TaskQueue} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/env node | ||
|
||
require('dotenv').config() | ||
const {sub} = require('date-fns') | ||
const mongo = require('../lib/util/mongo') | ||
const {setMongoCache} = require('../lib/tasks/mongo-cache') | ||
|
||
async function main() { | ||
await mongo.connect() | ||
|
||
const initCacheTs = sub(new Date(), {hours: 1}) | ||
await setMongoCache('detectConflictPublishedSince', initCacheTs) | ||
|
||
await mongo.disconnect() | ||
process.exit() | ||
} | ||
|
||
main().catch(error => { | ||
console.error(error) | ||
process.exit(1) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.