All files / daos reports.ts

88.89% Statements 8/9
50% Branches 1/2
100% Functions 4/4
100% Lines 8/8

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  1x   1x 1x         4x   2x 2x     2x 2x                
import { MyModels } from "../models";
import { NotFoundError } from "../types/errors";
 
export default function({ Reports }: MyModels) {
    return {
        addOne: (
            dumpsterID: number,
            userID: number,
            reason: string | undefined,
        ) => Reports.create({ dumpsterID, userID, reason }),
 
        getOne: async (dumpsterID: number, userID: number) => {
            const report = await Reports.findOne({
                where: { dumpsterID, userID },
            });
            Iif (!report) throw new NotFoundError("No such report");
            return {
                dumpsterID: report.dumpsterID,
                reason: report.reason,
                date: report.date,
            };
        },
    };
}