Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Init Payments, Reviews and Users Models #48

Merged
merged 17 commits into from
Oct 16, 2022
Empty file removed server/models/index.ts
Empty file.
70 changes: 70 additions & 0 deletions server/models/reviews.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import {
Model,
InferAttributes,
InferCreationAttributes,
CreationOptional,
DataTypes,
} from 'sequelize';
import sequelize from '../database/config/connection';

interface ReviewsModel
extends Model<
InferAttributes<ReviewsModel>,
InferCreationAttributes<ReviewsModel>
> {
id: CreationOptional<number>

title?: string

description?: Text

points?: number

is_shown?: boolean

creation_date?: Date

user_id?: number
}

const Reviews = sequelize.define<ReviewsModel>(
'Reviews',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
autoIncrement: true,
primaryKey: true,
},
title: {
type: DataTypes.STRING(255),
allowNull: false,
},
description: {
type: DataTypes.TEXT,
allowNull: true,
},
points: {
type: DataTypes.NUMBER,
allowNull: false,
validate: {
min: 1,
max: 5,
},
},
is_shown: {
type: DataTypes.BOOLEAN,
allowNull: false,
},
creation_date: {
type: DataTypes.DATE,
defaultValue: new Date(),
},
user_id: {
type: DataTypes.NUMBER,
allowNull: false,
},
},
);

export default Reviews;
54 changes: 54 additions & 0 deletions server/models/transactions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import {
Model,
InferAttributes,
InferCreationAttributes,
CreationOptional,
DataTypes,
} from 'sequelize';
import sequelize from '../database/config/connection';

interface TransactionsModel
extends Model<
InferAttributes<TransactionsModel>,
InferCreationAttributes<TransactionsModel>
> {
id: CreationOptional<number>

title?: string

description?: Text

creation_date?: Date

user_id?: number
}

const Transactions = sequelize.define<TransactionsModel>(
'Transactions',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
autoIncrement: true,
primaryKey: true,
},
title: {
type: DataTypes.STRING(255),
allowNull: false,
},
description: {
type: DataTypes.TEXT,
allowNull: true,
},
creation_date: {
type: DataTypes.DATE,
defaultValue: new Date(),
},
user_id: {
type: DataTypes.NUMBER,
allowNull: false,
},
},
);

export default Transactions;
79 changes: 79 additions & 0 deletions server/models/users.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import {
Model,
InferAttributes,
InferCreationAttributes,
CreationOptional,
DataTypes,
} from 'sequelize';
import sequelize from '../database/config/connection';

interface UsersModel
extends Model<
InferAttributes<UsersModel>,
InferCreationAttributes<UsersModel>
> {
id: CreationOptional<number>

first_name?: string

last_name?: string

email?: string

phone_number?: string

creation_date?: Date

roles?: 'ADMIN' | 'USER'

hased_password?: string
}

const Users = sequelize.define<UsersModel>(
'Transactions',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
autoIncrement: true,
primaryKey: true,
},
first_name: {
type: DataTypes.STRING(100),
allowNull: false,
},
last_name: {
type: DataTypes.STRING(100),
allowNull: false,
},
email: {
type: DataTypes.STRING(100),
allowNull: true,
validate: {
isEmail: true,
},
},
phone_number: {
type: DataTypes.STRING(14),
unique: true,
allowNull: false,
},
creation_date: {
type: DataTypes.DATE,
defaultValue: new Date(),
},
roles: {
type: DataTypes.ENUM('ADMIN', 'USER'),
allowNull: false,
},
hased_password: {
type: DataTypes.STRING(64),
validate: {
is: /^[0-9a-f]{64}$/i,
},
allowNull: false,
},
},
);

export default Users;