X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Futils.ts;h=2b172f6081e3eea7437a11010968af414ae76ab2;hb=2fb5b3a55aeebcc77f4b3a0c029bbf0738ef0063;hp=98170a00e14ec2c7275e8992b9874d3c2f3e1b09;hpb=1735c825726edaa0af5035cb6cbb0cc0db502c6d;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/utils.ts b/server/models/utils.ts index 98170a00e..2b172f608 100644 --- a/server/models/utils.ts +++ b/server/models/utils.ts @@ -118,6 +118,15 @@ function buildWhereIdOrUUID (id: number | string) { return validator.isInt('' + id) ? { id } : { uuid: id } } +function parseAggregateResult (result: any) { + if (!result) return 0 + + const total = parseInt(result + '', 10) + if (isNaN(total)) return 0 + + return total +} + // --------------------------------------------------------------------------- export { @@ -131,7 +140,8 @@ export { buildServerIdsFollowedBy, buildTrigramSearchIndex, buildWhereIdOrUUID, - isOutdated + isOutdated, + parseAggregateResult } // ---------------------------------------------------------------------------