All files / src/common/dto dto.js

90.9% Statements 10/11
85.71% Branches 6/7
100% Functions 1/1
90.9% Lines 10/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38    4x                     36x 36x     36x 30x     30x         36x 30x     36x   36x          
import { newLogger } from "@common/utils/logger.js";
 
const logger = newLogger("Dto|BaseDto");
 
/*
 * Properties:
 *      success: <boolean>
 *      info: [<string>]
 */
class BaseOutputDto {
    success;
 
    constructor(success, info = []) {
        info = Array.isArray(info) ? info : [info];
        let dtoInfo = [];
 
        // Save only the string values to a temporary array (dtoInfo)
        for (const k in info) {
            Iif (typeof info[k] !== "string") {
                logger.warn(`Info #${k} (${info[k]}: ${typeof info[k]}) must be a string.`);
            } else {
                dtoInfo.push(info[k]);
            }
        }
 
        // Check whether any value made it to the temporary array by checking if the first index is defined
        if (typeof dtoInfo[0] == "string") {
            this.info = dtoInfo;
        }
 
        this.success = Boolean(success);
 
        return this;
    }
}
 
export { BaseOutputDto };