-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2701 from w3f/will-v3.1.3
add tests, update swagger endpoints, use enums
- Loading branch information
Showing
33 changed files
with
758 additions
and
406 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
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 |
---|---|---|
@@ -1,33 +1,39 @@ | ||
import { EraModel } from "../models"; | ||
import { Era, EraModel } from "../models"; | ||
import logger from "../../logger"; | ||
|
||
export const setLastNominatedEraIndex = async ( | ||
index: number, | ||
): Promise<boolean> => { | ||
const data = await EraModel.findOne({}).lean(); | ||
if (!data) { | ||
const eraIndex = new EraModel({ | ||
lastNominatedEraIndex: index.toString(), | ||
when: Date.now(), | ||
}); | ||
await eraIndex.save(); | ||
return true; | ||
} | ||
|
||
await EraModel.findOneAndUpdate( | ||
{ lastNominatedEraIndex: /.*/ }, | ||
{ | ||
$set: { | ||
try { | ||
const data = await EraModel.findOne({}).lean(); | ||
if (!data) { | ||
const eraIndex = new EraModel({ | ||
lastNominatedEraIndex: index.toString(), | ||
when: Date.now(), | ||
nextNomination: Date.now() + 86400000, | ||
}); | ||
await eraIndex.save(); | ||
return true; | ||
} | ||
|
||
await EraModel.findOneAndUpdate( | ||
{ lastNominatedEraIndex: /.*/ }, | ||
{ | ||
$set: { | ||
lastNominatedEraIndex: index.toString(), | ||
when: Date.now(), | ||
nextNomination: Date.now() + 86400000, | ||
}, | ||
}, | ||
}, | ||
).exec(); | ||
return true; | ||
).exec(); | ||
return true; | ||
} catch (e) { | ||
logger.error( | ||
`Error setting last nominated era index: ${JSON.stringify(e)}`, | ||
); | ||
return false; | ||
} | ||
}; | ||
|
||
export const getLastNominatedEraIndex = async (): Promise<any> => { | ||
return EraModel.findOne({ lastNominatedEraIndex: /[0-9]+/ }) | ||
.lean() | ||
.exec(); | ||
export const getLastNominatedEraIndex = async (): Promise<Era | null> => { | ||
return EraModel.findOne({ lastNominatedEraIndex: /[0-9]+/ }).lean<Era>(); | ||
}; |
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
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
Oops, something went wrong.