Skip to content

Commit 78a38f8

Browse files
Copilotalexanmtz
andauthored
Convert models directory to TypeScript (#1373)
* Initial plan * Convert all model files from JavaScript to TypeScript Co-authored-by: alexanmtz <88840+alexanmtz@users.noreply.github.com> * Fix TypeScript compilation errors and add bcrypt types Co-authored-by: alexanmtz <88840+alexanmtz@users.noreply.github.com> * Fix foreign key definitions in TypeScript models - remove incorrectly added foreign keys Foreign key columns should only be defined in model schema when they were explicitly defined in the original JS models. Many models had foreign keys only in associations, not in the schema definition. Co-authored-by: alexanmtz <88840+alexanmtz@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: alexanmtz <88840+alexanmtz@users.noreply.github.com>
1 parent 4db3ab6 commit 78a38f8

50 files changed

Lines changed: 2818 additions & 932 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

package-lock.json

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@
132132
},
133133
"devDependencies": {
134134
"@playwright/test": "^1.53.0",
135+
"@types/bcrypt": "^6.0.0",
135136
"@types/bluebird": "^3.5.42",
136137
"@types/body-parser": "^1.19.6",
137138
"@types/chai": "^5.2.3",

src/models/assign.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/models/assign.ts

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import { Model, DataTypes, Optional, Sequelize } from 'sequelize'
2+
3+
export interface AssignAttributes {
4+
id: number
5+
status: string
6+
message?: string | null
7+
userId?: number | null
8+
TaskId?: number | null
9+
createdAt?: Date
10+
updatedAt?: Date
11+
}
12+
13+
export type AssignCreationAttributes = Optional<
14+
AssignAttributes,
15+
'id' | 'status' | 'message' | 'userId' | 'TaskId' | 'createdAt' | 'updatedAt'
16+
>
17+
18+
export default class Assign
19+
extends Model<AssignAttributes, AssignCreationAttributes>
20+
implements AssignAttributes
21+
{
22+
public id!: number
23+
public status!: string
24+
public message!: string | null
25+
public userId!: number | null
26+
public TaskId!: number | null
27+
public createdAt!: Date
28+
public updatedAt!: Date
29+
30+
static initModel(sequelize: Sequelize): typeof Assign {
31+
Assign.init(
32+
{
33+
id: {
34+
type: DataTypes.INTEGER,
35+
primaryKey: true,
36+
autoIncrement: true
37+
},
38+
status: {
39+
type: DataTypes.STRING,
40+
defaultValue: 'pending'
41+
},
42+
message: {
43+
type: DataTypes.STRING,
44+
allowNull: true
45+
},
46+
createdAt: {
47+
type: DataTypes.DATE,
48+
allowNull: false,
49+
defaultValue: DataTypes.NOW
50+
},
51+
updatedAt: {
52+
type: DataTypes.DATE,
53+
allowNull: false,
54+
defaultValue: DataTypes.NOW
55+
}
56+
},
57+
{
58+
sequelize,
59+
tableName: 'Assigns',
60+
timestamps: true
61+
}
62+
)
63+
return Assign
64+
}
65+
66+
static associate(models: any) {
67+
models.Assign.belongsTo(models.User, { foreignKey: 'userId' })
68+
models.Assign.belongsTo(models.Task, { foreignKey: 'TaskId' })
69+
}
70+
}
71+
72+
module.exports = (sequelize: Sequelize) => {
73+
return Assign.initModel(sequelize)
74+
}
75+
module.exports.Assign = Assign
76+
module.exports.default = Assign

src/models/coupon.js

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/models/coupon.ts

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import { Model, DataTypes, Optional, Sequelize } from 'sequelize'
2+
3+
export interface CouponAttributes {
4+
id: number
5+
code?: string | null
6+
amount?: string | null
7+
expires?: boolean | null
8+
validUntil?: Date | null
9+
times?: number | null
10+
createdAt?: Date
11+
updatedAt?: Date
12+
}
13+
14+
export type CouponCreationAttributes = Optional<
15+
CouponAttributes,
16+
'id' | 'code' | 'amount' | 'expires' | 'validUntil' | 'times' | 'createdAt' | 'updatedAt'
17+
>
18+
19+
export default class Coupon
20+
extends Model<CouponAttributes, CouponCreationAttributes>
21+
implements CouponAttributes
22+
{
23+
public id!: number
24+
public code!: string | null
25+
public amount!: string | null
26+
public expires!: boolean | null
27+
public validUntil!: Date | null
28+
public times!: number | null
29+
public createdAt!: Date
30+
public updatedAt!: Date
31+
32+
static initModel(sequelize: Sequelize): typeof Coupon {
33+
Coupon.init(
34+
{
35+
id: {
36+
type: DataTypes.INTEGER,
37+
primaryKey: true,
38+
autoIncrement: true
39+
},
40+
code: {
41+
type: DataTypes.STRING,
42+
allowNull: true
43+
},
44+
amount: {
45+
type: DataTypes.DECIMAL,
46+
allowNull: true
47+
},
48+
expires: {
49+
type: DataTypes.BOOLEAN,
50+
allowNull: true
51+
},
52+
validUntil: {
53+
type: DataTypes.DATE,
54+
allowNull: true
55+
},
56+
times: {
57+
type: DataTypes.INTEGER,
58+
allowNull: true
59+
},
60+
createdAt: {
61+
type: DataTypes.DATE,
62+
allowNull: false,
63+
defaultValue: DataTypes.NOW
64+
},
65+
updatedAt: {
66+
type: DataTypes.DATE,
67+
allowNull: false,
68+
defaultValue: DataTypes.NOW
69+
}
70+
},
71+
{
72+
sequelize,
73+
tableName: 'Coupons',
74+
timestamps: true
75+
}
76+
)
77+
return Coupon
78+
}
79+
80+
static associate(models: any) {
81+
models.Coupon.hasMany(models.Order, { foreignKey: 'couponId' })
82+
}
83+
}
84+
85+
module.exports = (sequelize: Sequelize) => {
86+
return Coupon.initModel(sequelize)
87+
}
88+
module.exports.Coupon = Coupon
89+
module.exports.default = Coupon

src/models/history.js

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/models/history.ts

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import { Model, DataTypes, Optional, Sequelize } from 'sequelize'
2+
3+
export interface HistoryAttributes {
4+
id: number
5+
type?: string | null
6+
fields?: string[] | null
7+
oldValues?: string[] | null
8+
newValues?: string[] | null
9+
TaskId: number
10+
createdAt?: Date
11+
updatedAt?: Date
12+
}
13+
14+
export type HistoryCreationAttributes = Optional<
15+
HistoryAttributes,
16+
'id' | 'type' | 'fields' | 'oldValues' | 'newValues' | 'createdAt' | 'updatedAt'
17+
>
18+
19+
export default class History
20+
extends Model<HistoryAttributes, HistoryCreationAttributes>
21+
implements HistoryAttributes
22+
{
23+
public id!: number
24+
public type!: string | null
25+
public fields!: string[] | null
26+
public oldValues!: string[] | null
27+
public newValues!: string[] | null
28+
public TaskId!: number
29+
public createdAt!: Date
30+
public updatedAt!: Date
31+
32+
static initModel(sequelize: Sequelize): typeof History {
33+
History.init(
34+
{
35+
id: {
36+
type: DataTypes.INTEGER,
37+
primaryKey: true,
38+
autoIncrement: true
39+
},
40+
type: {
41+
type: DataTypes.STRING,
42+
allowNull: true
43+
},
44+
fields: {
45+
type: DataTypes.ARRAY(DataTypes.TEXT),
46+
allowNull: true
47+
},
48+
oldValues: {
49+
type: DataTypes.ARRAY(DataTypes.TEXT),
50+
allowNull: true
51+
},
52+
newValues: {
53+
type: DataTypes.ARRAY(DataTypes.TEXT),
54+
allowNull: true
55+
},
56+
TaskId: {
57+
type: DataTypes.INTEGER,
58+
references: {
59+
model: 'Tasks',
60+
key: 'id'
61+
},
62+
allowNull: false
63+
},
64+
createdAt: {
65+
type: DataTypes.DATE,
66+
allowNull: false,
67+
defaultValue: DataTypes.NOW
68+
},
69+
updatedAt: {
70+
type: DataTypes.DATE,
71+
allowNull: false,
72+
defaultValue: DataTypes.NOW
73+
}
74+
},
75+
{
76+
sequelize,
77+
tableName: 'Histories',
78+
timestamps: true
79+
}
80+
)
81+
return History
82+
}
83+
84+
static associate(models: any) {
85+
models.History.belongsTo(models.Task)
86+
}
87+
}
88+
89+
module.exports = (sequelize: Sequelize) => {
90+
return History.initModel(sequelize)
91+
}
92+
module.exports.History = History
93+
module.exports.default = History

src/models/label.js

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)