X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Futils.ts;h=2b172f6081e3eea7437a11010968af414ae76ab2;hb=cbe94af85a9a7ca4aeaf783a6f8ed5954cba2f44;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 } // ---------------------------------------------------------------------------