-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6219647
commit f00fccf
Showing
12 changed files
with
211 additions
and
26 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
import Animal from "./models/Animal"; | ||
import Institution from "./models/Institution"; | ||
import User from "./models/User"; | ||
import UserRole from "./models/UserRole"; | ||
export const entities: any[] = [ | ||
User, | ||
Institution, | ||
UserRole, | ||
Animal, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { Model, DataTypes } from 'sequelize'; | ||
import database from '../database'; | ||
|
||
class Institution extends Model { | ||
public id!: number; | ||
public name!: string; | ||
public cnpj?: string; | ||
public description!: string; | ||
public phone?: string; | ||
public site?: string; | ||
public email?: string; | ||
public image?: string; | ||
public receive_volunteers!: string; | ||
} | ||
|
||
Institution.init( | ||
{ | ||
id: { | ||
type: DataTypes.INTEGER, | ||
primaryKey: true, | ||
autoIncrement: true, | ||
}, | ||
name: { | ||
type: DataTypes.STRING, | ||
allowNull: false, | ||
}, | ||
cnpj:{ | ||
type: DataTypes.STRING, | ||
allowNull: true, | ||
}, | ||
description:{ | ||
type: DataTypes.STRING, | ||
allowNull: false, | ||
}, | ||
phone:{ | ||
type: DataTypes.STRING, | ||
allowNull: true, | ||
}, | ||
site:{ | ||
type: DataTypes.STRING, | ||
allowNull: true, | ||
}, | ||
image:{ | ||
type: DataTypes.BLOB, | ||
allowNull: true, | ||
}, | ||
receive_volunteers:{ | ||
type: DataTypes.BOOLEAN, | ||
allowNull: false, | ||
defaultValue: true, | ||
}, | ||
}, | ||
{ | ||
tableName: 'institution', | ||
sequelize: database.connection, | ||
} | ||
); | ||
|
||
export default Institution; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { Model, DataTypes } from 'sequelize'; | ||
import database from '../database'; | ||
import User from './User'; | ||
import Institution from './Institution'; | ||
|
||
class UserRole extends Model { | ||
public id!: number; | ||
public idUser!: number; | ||
public idInstitution?: number; | ||
public idRole?: number; | ||
} | ||
|
||
UserRole.init( | ||
{ | ||
id: { | ||
type: DataTypes.INTEGER, | ||
primaryKey: true, | ||
autoIncrement: true, | ||
}, | ||
idUser:{ | ||
type: DataTypes.INTEGER, | ||
allowNull: false, | ||
}, | ||
idInstitution:{ | ||
type: DataTypes.INTEGER, | ||
allowNull: true, | ||
}, | ||
idRole:{ | ||
type: DataTypes.INTEGER, | ||
allowNull: false, | ||
} | ||
}, | ||
{ | ||
tableName: 'user_role', | ||
sequelize: database.connection, | ||
} | ||
); | ||
|
||
User.hasMany(UserRole, { | ||
foreignKey:'idUser', | ||
as: 'userRoles' | ||
}); | ||
|
||
Institution.hasMany(UserRole, { | ||
foreignKey:'idInstitution', | ||
}); | ||
|
||
|
||
export default UserRole; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export enum Roles { | ||
User = 1, | ||
Volunteer = 2, | ||
Administrator = 3, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { NextFunction } from "express"; | ||
import { AuthenticatedRequest } from "../../.."; | ||
import { Request, Response } from 'express'; | ||
import { Roles } from "../../enums/Roles"; | ||
|
||
export default function CheckAclPermission(role: Roles) { | ||
return function (req: Request, res: Response, next: NextFunction) { | ||
const authenticatedRequest = req as unknown as AuthenticatedRequest; | ||
const { userRoles } = authenticatedRequest.user!; | ||
|
||
if (userRoles.some(x => x.idRole === role)) { | ||
return next(); | ||
} | ||
|
||
return res.status(403).json({ message: 'Perfil sem permissão!' }); | ||
} | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters