/ src / models / masters.model.ts
masters.model.ts
 1  // See http://docs.sequelizejs.com/en/latest/docs/models-definition/
 2  // for more of what you can do here.
 3  import {
 4  	DataTypes,
 5  	type Model,
 6  	type ModelStatic,
 7  	type Optional,
 8  	type Sequelize,
 9  } from "sequelize";
10  
11  import { UUID } from "sequelize";
12  import { v4 as uuidv4 } from "uuid";
13  
14  import type { Application } from "../declarations";
15  
16  export interface MasterAttributes {
17  	id: number;
18  	text: string;
19  	deletedAt: Date;
20  }
21  
22  interface MasterCreationAttributes extends Optional<MasterAttributes, "id"> {}
23  
24  /**
25   * @swagger
26   * components:
27   *   schemas:
28   *     Master:
29   *       type: object
30   *       properties:
31   *         id:
32   *           type: integer
33   *           format: int64
34   *         text:
35   *           type: string
36   *         deletedAt:
37   *           type: string
38   *           format: date-time
39   */
40  export default function (
41  	app: Application,
42  ): ModelStatic<Model<MasterAttributes, MasterCreationAttributes>> {
43  	const sequelizeClient: Sequelize = app.get("sequelizeClient");
44  	const masters = sequelizeClient.define<
45  		Model<MasterAttributes, MasterCreationAttributes>
46  	>(
47  		"masters",
48  		{
49  			id: {
50  				type: DataTypes.UUID,
51  				defaultValue: uuidv4(),
52  				primaryKey: true,
53  				unique: true,
54  				allowNull: false,
55  			},
56  			text: {
57  				type: DataTypes.STRING,
58  				allowNull: false,
59  			},
60  			deletedAt: {
61  				type: DataTypes.DATE,
62  			},
63  		},
64  		{
65  			hooks: {
66  				// biome-ignore lint/suspicious/noExplicitAny: <explanation>
67  				beforeCount(options: any) {
68  					options.raw = true;
69  				},
70  			},
71  		},
72  	);
73  
74  	// biome-ignore lint/suspicious/noExplicitAny: <explanation>
75  	(masters as any).associate = (models: any) => {
76  		// Define associations here
77  		// See http://docs.sequelizejs.com/en/latest/docs/associations/
78  	};
79  
80  	return masters;
81  }