All files / models dumpsters.ts

100% Statements 8/8
100% Branches 0/0
100% Functions 2/2
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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 15511x                   11x                                                                                         11x 11x                                                                                                                               11x       11x                                           11x 11x              
import { Sequelize, DataTypes, Optional, Model, ModelStatic } from "sequelize";
import {
    DumpsterTypeAttributes,
    DumpsterTypeCreationAttributes,
} from "./dumpsterTypes";
import { StoreTypeAttributes, StoreTypeCreationAttributes } from "./storeTypes";
import {
    DumpsterPositionAttributes,
    DumpsterPositionCreationAttributes,
} from "./DumpsterPositions";
import { Categories } from "./Categories";
import { UserAttributes, UserCreationAttributes } from "./Users";
 
export interface DumpsterAttributes {
    revisionID: number;
    dumpsterID: number;
    position: object;
    name: string;
    dateAdded: Date;
    dateUpdated: Date;
    dumpsterTypeID: number;
    storeTypeID: number;
    locked: boolean;
    positiveStoreViewOnDiving: boolean | null;
    emptyingSchedule: string;
    cleanliness: number;
    userID: number | null;
    info: string;
}
 
export interface DumpsterCreationAttributes
    extends Optional<
        DumpsterAttributes,
        "revisionID" | "dateAdded" | "dateUpdated"
    > {}
 
class Dumpsters extends Model<DumpsterAttributes, DumpsterCreationAttributes>
    implements DumpsterAttributes {
    revisionID!: number;
    dumpsterID!: number;
    position!: object;
    name!: string;
    dateAdded!: Date;
    dateUpdated!: Date;
    dumpsterTypeID!: number;
    storeTypeID!: number;
    locked!: boolean;
    positiveStoreViewOnDiving!: boolean | null;
    emptyingSchedule!: string;
    cleanliness!: number;
    userID!: number | null;
    info!: string;
}
 
// Inject Sequelize
export function init(sequelize: Sequelize) {
    Dumpsters.init(
        {
            revisionID: {
                type: DataTypes.INTEGER.UNSIGNED,
                autoIncrement: true,
                primaryKey: true,
            },
            dumpsterID: {
                type: DataTypes.INTEGER.UNSIGNED,
            },
            position: {
                type: DataTypes.GEOMETRY("POINT"),
                allowNull: false,
            },
            name: {
                type: DataTypes.STRING,
                defaultValue: 0,
                allowNull: false,
            },
            dateAdded: {
                type: DataTypes.DATE,
                allowNull: false,
                defaultValue: Sequelize.fn("now"),
            },
            dateUpdated: {
                type: DataTypes.DATE,
                allowNull: false,
                defaultValue: Sequelize.fn("now"),
            },
            dumpsterTypeID: {
                type: DataTypes.INTEGER.UNSIGNED,
                allowNull: false,
            },
            storeTypeID: {
                type: DataTypes.INTEGER.UNSIGNED,
                allowNull: false,
            },
            locked: {
                type: DataTypes.BOOLEAN,
                defaultValue: false,
                allowNull: false,
            },
            positiveStoreViewOnDiving: {
                type: DataTypes.BOOLEAN,
            },
            emptyingSchedule: {
                type: DataTypes.STRING,
            },
            cleanliness: {
                type: DataTypes.TINYINT.UNSIGNED,
                allowNull: false,
            },
            userID: {
                type: DataTypes.NUMBER,
            },
            info: {
                type: DataTypes.TEXT,
            },
        },
        {
            sequelize,
            tableName: "Dumpsters",
        },
    );
    return Dumpsters;
}
 
// The type is not defined yet, so use a substitute
export function associate({
    DumpsterTypes,
    StoreTypes,
    DumpsterCategories,
    DumpsterPositions,
    Users,
}: {
    DumpsterTypes: ModelStatic<
        Model<DumpsterTypeAttributes, DumpsterTypeCreationAttributes>
    >;
    StoreTypes: ModelStatic<
        Model<StoreTypeAttributes, StoreTypeCreationAttributes>
    >;
    DumpsterPositions: ModelStatic<
        Model<DumpsterPositionAttributes, DumpsterPositionCreationAttributes>
    >;
    Users: ModelStatic<Model<UserAttributes, UserCreationAttributes>>;
    DumpsterCategories: ModelStatic<Model<any, any>>;
}) {
    // do associations like
    // Thing.hasMany()
    // using the supplied Models object
    Dumpsters.hasMany(DumpsterPositions, { foreignKey: "revisionID" });
    Dumpsters.belongsToMany(Categories, {
        as: "categories",
        // @ts-ignore
        through: DumpsterCategories,
        foreignKey: "revisionID",
    });
}