Skip to content

Commit

Permalink
added: feature report
Browse files Browse the repository at this point in the history
	modified:   @types/global.d.ts
	modified:   app.js
	modified:   data/rbac-ext.csv
	modified:   database/migrations/20220719152230-create-admins.js
	modified:   database/migrations/20220719152231-create-supervisors.js
	modified:   database/migrations/20220719152232-create-projects.js
	renamed:    database/migrations/20220719152233-create-tasks.js -> database/migrations/20220719152233-create-reports.js
	modified:   database/models/admins.js
	modified:   database/models/projects.js
	renamed:    database/models/tasks.js -> database/models/reports.js
	modified:   database/models/supervisors.js
	deleted:    database/models/users.js
	modified:   database/seeders/20220705132749-init.js
	modified:   ecosystem.config.js
	modified:   jsconfig.json
	modified:   lib/authorization.js
	new file:   lib/backuper.js
	modified:   lib/logger.js
	new file:   lib/scheming.js
	modified:   lib/validator.js
	new file:   middleware/auth.js
	modified:   package-lock.json
	modified:   package.json
	modified:   routes/api/v1/admins.js
	modified:   routes/api/v1/members.js
	new file:   routes/api/v1/models.js
	modified:   routes/api/v1/projects.js
	new file:   routes/api/v1/reports.js
	new file:   routes/api/v1/resources.js
	modified:   routes/api/v1/supervisors.js
	deleted:    routes/api/v1/tasks.js
	new file:   routes/api/v1/users.js
	new file:   schema/v2/auth.json
	new file:   schema/v2/index.json
	new file:   schema/v2/resources.json
	new file:   type/v2/index.d.ts
  • Loading branch information
AnasMubarakYasin committed Jul 30, 2022
1 parent d2883fc commit 93cf618
Show file tree
Hide file tree
Showing 36 changed files with 2,723 additions and 497 deletions.
38 changes: 25 additions & 13 deletions @types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { SchemaTasks } from "../type/v1/tasks";
import { SchemaAdmins } from "../type/v1/admins";
import { SchemaSupervisors } from "../type/v1/supervisors";

import * as TypeV2 from "../type/v2/index";

declare global {
namespace NodeJS {
interface ProcessEnv {
Expand All @@ -23,6 +25,9 @@ declare global {
PATH_API: string;
URL_BS_API: string;
DB_URL: string;
SERVER_MODE: string;
SERVER_HAS_ENV: boolean;
JWT_KEY: string;
}
}
namespace App {
Expand All @@ -33,27 +38,34 @@ declare global {
}
module Models {
type AttrDef = "id" | "createdAt" | "updatedAt";
type UsersAttributes = {
id: number;
type UsersInterop = {
username: string;
password: string;
image: string;
name: string;
email: string;
nip: string;
role: string;
password: string;
};

type UserCreationAttributes = Optional<UsersAttributes, "id">;

class Users extends Model<UsersAttributes, UserCreationAttributes> {}
class Projects extends Model<
SchemaProjects,
Optional<SchemaProjects, AttrDef>
TypeV2.Projects,
Optional<TypeV2.ProjectsCreate, AttrDef>
> {}
class Reports extends Model<
TypeV2.Reports,
Optional<TypeV2.ReportsCreate, AttrDef>
> {}
class Admins extends Model<
TypeV2.Admins,
Optional<TypeV2.AdminsCreate, AttrDef>
> {}
class Supervisors extends Model<
TypeV2.Supervisors,
Optional<TypeV2.SupervisorsCreate, AttrDef>
> {}
class Tasks extends Model<SchemaTasks, Optional<SchemaTasks, AttrDef>> {}
class Admins extends Model<SchemaAdmins, Optional<SchemaAdmins, AttrDef>> {}
class Supervisors extends Model<SchemaSupervisors, Optional<SchemaSupervisors, AttrDef>> {}

type CtorProjects = ModelStatic<Projects>;
type CtorTasks = ModelStatic<Tasks>;
type CtorReports = ModelStatic<Reports>;
type CtorAdmins = ModelStatic<Admins>;
type CtorSupervisors = ModelStatic<Supervisors>;
}
Expand Down
27 changes: 15 additions & 12 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,20 @@ const limitter = require("#root/lib/limitter");
const app = express();
const { env } = process;

const model_users = require("#model/users");
const model_admins = require("#model/admins");
const model_supervisors = require("#model/supervisors");
const model_projects = require("#model/projects");
const model_tasks = require("#model/tasks");
const model_reports = require("#root/database/models/reports");

// const routesApiV0Account = require("#routes/api/v0/account");
const routes_api_v1_members = require("#routes/api/v1/members");
const routes_api_v1_admins = require("#routes/api/v1/admins");
const routes_api_v1_supervisors = require("#routes/api/v1/supervisors");
const routes_api_v1_projects = require("#routes/api/v1/projects");
const routes_api_v1_tasks = require("#routes/api/v1/tasks");
// const routes_api_v1_members = require("#api/v1/members");
const routes_api_v1_users = require("#api/v1/users");
const routes_api_v1_resources = require("#api/v1/resources");
const routes_api_v1_models = require("#api/v1/models");
const routes_api_v1_admins = require("#api/v1/admins");
const routes_api_v1_supervisors = require("#api/v1/supervisors");
const routes_api_v1_projects = require("#api/v1/projects");
const routes_api_v1_reports = require("#api/v1/reports");
// const routesLangEnAccount = require("#routes/lang/en/account");

const routes_setting = require("#routes/setting/index");
Expand All @@ -48,11 +50,10 @@ async function init() {
name: "app",
url: env.DB_URL,
model_loaders: [
model_users,
model_admins,
model_supervisors,
model_projects,
model_tasks,
model_reports,
],
logger: logger,
});
Expand Down Expand Up @@ -105,16 +106,18 @@ async function init() {
})
);
app.use("/public", express.static(path.join(__dirname, "public")));
app.use("/resources", express.static(path.join(__dirname, "storage")));

app.use("/setting", await routes_setting(app));

app.use("/api", express.json(), express.urlencoded({ extended: true }));
app.use("/api/v1/members", await routes_api_v1_members(app));
// app.use("/api/v1/members", await routes_api_v1_members(app));
app.use("/api/v1/users", await routes_api_v1_users(app));
app.use("/api/v1/resources", await routes_api_v1_resources(app));
app.use("/api/v1/models", await routes_api_v1_models(app));
app.use("/api/v1/admins", await routes_api_v1_admins(app));
app.use("/api/v1/supervisors", await routes_api_v1_supervisors(app));
app.use("/api/v1/projects", await routes_api_v1_projects(app));
app.use("/api/v1/tasks", await routes_api_v1_tasks(app));
app.use("/api/v1/reports", await routes_api_v1_reports(app));
app.use("/api", Interchange.not_found_middle(), Interchange.error_middle());

app.use(function (req, res, nx) {
Expand Down
23 changes: 8 additions & 15 deletions data/rbac-ext.csv
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
p, root, all, read|write, one|all

p, admin, users, read|write, one|all
p, admin, roles, read|write, one|all
p, admin, tasks, read|write, one|all
p, admin, projects, read|write, one|all
p, admin, members, read|write, one|all
p, admin, admins, read|write, one|all
p, admin, supervisors, read|write, one|all
p, admin, projects, read|write, one|all
p, admin, reports, read|write, one|all
p, admin, models, read|write, one|all

p, supervisor, accounts, read|write, one
p, supervisor, supervisors, read|write, one
p, supervisor, projects, read, one|all
p, supervisor, tasks, read, one|all

p, officer, accounts, read|write, one
p, officer, projects, read|write, one
p, officer, tasks, read|write, one

p, Common, accounts, read|write, one
p, Common, public, read, one|all

p, Anonymous, public, read, one|all
p, supervisor, reports, read|write, one|all

g, User, Common
g, system, root
11 changes: 9 additions & 2 deletions database/migrations/20220719152230-create-admins.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,17 @@ module.exports = {
type: Sequelize.STRING,
allowNull: false,
},
email: {
image: {
type: Sequelize.STRING,
allowNull: false,
},
name: {
type: Sequelize.STRING,
allowNull: false,
},
nip: {
type: Sequelize.STRING,
allowNull: false,
unique: true,
},
role: {
type: Sequelize.STRING,
Expand Down
15 changes: 11 additions & 4 deletions database/migrations/20220719152231-create-supervisors.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,21 @@ module.exports = {
type: Sequelize.STRING,
allowNull: false,
},
role: {
image: {
type: Sequelize.STRING,
defaultValue: "supervisor",
allowNull: false,
},
email: {
name: {
type: Sequelize.STRING,
allowNull: false,
unique: true,
},
nip: {
type: Sequelize.STRING,
allowNull: false,
},
role: {
type: Sequelize.STRING,
defaultValue: "supervisor",
},

created_at: {
Expand Down
10 changes: 5 additions & 5 deletions database/migrations/20220719152232-create-projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,7 @@ module.exports = {
allowNull: false,
},
activity: {
type: Sequelize.TEXT("long"),
allowNull: false,
},
obstacles: {
type: Sequelize.TEXT("long"),
type: Sequelize.TEXT,
allowNull: false,
},
status: {
Expand All @@ -75,6 +71,10 @@ module.exports = {
type: Sequelize.ARRAY(Sequelize.STRING),
allowNull: false,
},
proposal: {
type: Sequelize.STRING,
allowNull: false,
},

created_at: {
allowNull: false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
"use strict";
module.exports = {
/**
* @param {import('sequelize').QueryInterface} queryInterface
* @param {import('sequelize').DataTypes} Sequelize
*/
async up(queryInterface, Sequelize) {
await queryInterface.createTable("tasks", {
await queryInterface.createTable("reports", {
id: {
allowNull: false,
autoIncrement: true,
Expand All @@ -14,16 +18,28 @@ module.exports = {
references: { model: "projects", key: "id" },
},

order: {
type: Sequelize.INTEGER,
project_copy: {
type: Sequelize.JSON,
allowNull: false,
},
reported_at: {
type: Sequelize.DATEONLY,
allowNull: false,
},
preparation: {
type: Sequelize.TEXT,
allowNull: false,
},
base_building: {
type: Sequelize.TEXT,
allowNull: false,
},
note: {
type: Sequelize.TEXT("medium"),
structure: {
type: Sequelize.TEXT,
allowNull: false,
},
done: {
type: Sequelize.BOOLEAN,
supervisor_instruction: {
type: Sequelize.TEXT,
allowNull: false,
},

Expand All @@ -38,6 +54,6 @@ module.exports = {
});
},
async down(queryInterface, Sequelize) {
await queryInterface.dropTable("tasks");
await queryInterface.dropTable("reports");
},
};
11 changes: 9 additions & 2 deletions database/models/admins.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,17 @@ module.exports = (sequelize, DataTypes) => {
type: DataTypes.STRING,
allowNull: false,
},
email: {
image: {
type: DataTypes.STRING,
allowNull: false,
},
name: {
type: DataTypes.STRING,
allowNull: false,
},
nip: {
type: DataTypes.STRING,
allowNull: false,
unique: true,
},
role: {
type: DataTypes.STRING,
Expand Down
14 changes: 7 additions & 7 deletions database/models/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = (sequelize, DataTypes) => {
*/
static associate(models) {
// define association here
this.hasMany(models.tasks, {
this.hasMany(models.reports, {
foreignKey: {
name: "id_projects",
allowNull: false,
Expand Down Expand Up @@ -64,19 +64,15 @@ module.exports = (sequelize, DataTypes) => {
allowNull: false,
},
activity: {
type: DataTypes.TEXT("long"),
allowNull: false,
},
obstacles: {
type: DataTypes.TEXT("long"),
type: DataTypes.TEXT,
allowNull: false,
},
status: {
type: DataTypes.STRING,
allowNull: false,
},
progress: {
type: DataTypes.SMALLINT,
type: DataTypes.TINYINT,
allowNull: false,
},
fund_source: {
Expand All @@ -95,6 +91,10 @@ module.exports = (sequelize, DataTypes) => {
type: DataTypes.ARRAY(DataTypes.STRING),
allowNull: false,
},
proposal: {
type: DataTypes.STRING,
allowNull: false,
},
},
{
sequelize,
Expand Down
Loading

0 comments on commit 93cf618

Please sign in to comment.