Auth: added

This commit is contained in:
2023-12-31 17:16:15 +01:00
parent 5c769bfa2f
commit dabd5ea0f0
17 changed files with 771 additions and 75 deletions

44
api/src/models/Client.ts Normal file
View File

@@ -0,0 +1,44 @@
import { DataTypes, Model } from 'sequelize'
import path from 'path'
import db from '../config/sequelize.config'
import User from './User'
class Instance extends Model {}
Instance.init(
{
_id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
allowNull: false,
unique: true
},
name: {
type: DataTypes.STRING,
allowNull: false
},
hourlyRate: {
type: DataTypes.INTEGER,
allowNull: true
},
contact: {
type: DataTypes.STRING,
allowNull: true
},
author_id: {
type: DataTypes.UUID,
allowNull: false,
references: {
model: User,
key: '_id'
}
}
},
{
sequelize: db,
tableName: path.basename(__filename).split('.')[0].toLowerCase()
}
)
export default Instance

49
api/src/models/Project.ts Normal file
View File

@@ -0,0 +1,49 @@
import { DataTypes, Model } from 'sequelize'
import path from 'path'
import db from '../config/sequelize.config'
import User from './User'
import Client from './Client'
class Instance extends Model {}
Instance.init(
{
_id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
allowNull: false,
unique: true
},
name: {
type: DataTypes.STRING,
allowNull: false
},
hourlyRate: {
type: DataTypes.INTEGER,
allowNull: true
},
client_id: {
type: DataTypes.UUID,
allowNull: false,
references: {
model: Client,
key: '_id'
}
},
author_id: {
type: DataTypes.UUID,
allowNull: false,
references: {
model: User,
key: '_id'
}
}
},
{
sequelize: db,
tableName: path.basename(__filename).split('.')[0].toLowerCase()
}
)
export default Instance

View File

@@ -1,6 +1,9 @@
import { DataTypes, Model } from 'sequelize'
import path from 'path'
import db from '../config/sequelize.config'
import User from './User'
import Client from './Client'
import Project from './Project'
class Instance extends Model {}
@@ -14,14 +17,6 @@ Instance.init(
unique: true
},
title: {
type: DataTypes.STRING,
allowNull: false
},
client: {
type: DataTypes.STRING,
allowNull: true
},
project: {
type: DataTypes.STRING,
allowNull: true
},
@@ -32,6 +27,22 @@ Instance.init(
timeEnd: {
type: DataTypes.BIGINT,
allowNull: true
},
project_id: {
type: DataTypes.UUID,
allowNull: true,
references: {
model: Project,
key: '_id'
}
},
author_id: {
type: DataTypes.UUID,
allowNull: false,
references: {
model: User,
key: '_id'
}
}
},
{

View File

@@ -8,28 +8,29 @@ Instance.init(
{
_id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
allowNull: false,
unique: true,
unique: true
},
username: {
type: DataTypes.STRING,
allowNull: false,
allowNull: false
},
password: {
type: DataTypes.STRING,
allowNull: false,
allowNull: false
},
email: {
type: DataTypes.STRING,
allowNull: false,
unique: true,
},
unique: true
}
},
{
sequelize: db,
tableName: path.basename(__filename).split('.')[0].toLowerCase(),
},
tableName: path.basename(__filename).split('.')[0].toLowerCase()
}
)
export default Instance