Skip to content

Commit

Permalink
Pretty up form and login
Browse files Browse the repository at this point in the history
  • Loading branch information
datajohnson committed May 29, 2024
1 parent 2a51557 commit 7433af2
Show file tree
Hide file tree
Showing 13 changed files with 329 additions and 119 deletions.
71 changes: 34 additions & 37 deletions api/src/data/models/user-model.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,45 @@
export interface User {
EMAIL: string;
USER_ID: string;
FIRST_NAME: string;
LAST_NAME: string;
STATUS: UserStatus;
IS_ADMIN: boolean | string;
YNET_ID: string;
CREATE_DATE: Date;
ROLE: string;

display_name?: string;
surveys?: number[];
}

export enum UserStatus {
ACTIVE = "Active",
INACTIVE = "Inactive",
email: string;
auth_subject: string;
first_name: string;
last_name: string;
display_name: string;
title: string;
department: string;
division: string;
branch: string;
unit: string;
is_active: boolean | string;
}

export interface User_Create {
EMAIL: string;
USER_ID: string;
FIRST_NAME: string;
LAST_NAME: string;
STATUS: UserStatus;
CREATE_DATE: Date;
IS_ADMIN: string;
ROLE: string;
email: string;
auth_subject: string;
first_name: string;
last_name: string;
display_name: string;
title: string;
department: string;
division: string;
branch: string;
unit: string;
is_active: boolean | string;
}

export interface User_Update {
FIRST_NAME: string;
LAST_NAME: string;
STATUS: UserStatus;
YNET_ID: string;
ROLE: string;
USER_ID?: string;
}

export interface UserRole {
email: string;
role: string;
auth_subject: string;
first_name: string;
last_name: string;
display_name: string;
title: string;
department: string;
division: string;
branch: string;
unit: string;
is_active: boolean | string;
}

export class UserHelper {
/* export class UserHelper {
fromDTO(dto: any): User {
return {
EMAIL: dto.EMAIL,
Expand All @@ -58,3 +54,4 @@ export class UserHelper {
};
}
}
*/
49 changes: 30 additions & 19 deletions api/src/middleware/authz.middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import axios from "axios";
import jwksRsa, { type GetVerificationKey } from "jwks-rsa";
import { AUTH0_DOMAIN, AUTH0_AUDIENCE } from "../config";
import { UserService } from "../services";
import { UserStatus } from "../data/models";

console.log(AUTH0_AUDIENCE, AUTH0_DOMAIN);

Expand Down Expand Up @@ -45,39 +44,51 @@ export async function loadUser(req: Request, res: Response, next: NextFunction)

let u = await db.getBySub(sub);

console.log("SUB", sub, u);

if (u) {
req.user = { ...req.auth, ...u };
} else {
if (!email) email = `${first_name}.${last_name}@yukon-no-email.ca`;

let e = await db.getByEmail(email);
console.log("EMAIL", email, e);

if (e && e.USER_ID == "SUB_MISSING") {
if (e && e.auth_subject == "SUB_MISSING") {
req.user = { ...req.auth, ...e };

await db.update(email, {
USER_ID: sub,
FIRST_NAME: e.FIRST_NAME,
LAST_NAME: e.LAST_NAME,
ROLE: e.ROLE,
STATUS: e.STATUS,
YNET_ID: e.YNET_ID,
auth_subject: sub,
first_name: e.first_name,
last_name: e.last_name,
display_name: `${first_name} ${last_name}`,
department: "",
division: "",
branch: "",
unit: "",
is_active: true,
title: "",
});

return next();
}

/* u = await db.create({
EMAIL: email,
USER_ID: sub,
STATUS: UserStatus.INACTIVE,
FIRST_NAME: first_name,
LAST_NAME: last_name,
CREATE_DATE: new Date(),
IS_ADMIN: "N",
ROLE: "",
});
req.user = { ...req.user, ...u }; */
let newUser = {
email: email,
auth_subject: sub,
first_name: first_name,
last_name: last_name,
display_name: `${first_name} ${last_name}`,
department: "",
division: "",
branch: "",
unit: "",
is_active: true,
title: "",
};

await db.create(newUser);
req.user = { ...req.user, ...newUser };
}
} else {
console.log("Payload from Auth0 is strange or failed for", req.auth);
Expand Down
18 changes: 7 additions & 11 deletions api/src/routes/user-router.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
import express, { Request, Response } from "express";
import { UserService } from "../services";
import { UserStatus } from "../data/models";
import { ReturnValidationErrors } from "../middleware";
import { param } from "express-validator";

export const userRouter = express.Router();
const db = new UserService();

userRouter.get("/me", async (req: Request, res: Response) => {
return res.json({ data: { ...req.user, surveys: await db.getSurveysByEmail(req.user.EMAIL) } });
return res.json({ data: req.user });
});

userRouter.get("/", async (req: Request, res: Response) => {
let list = await db.getAll();

for (let l of list) {
l.display_name = `${l.FIRST_NAME} ${l.LAST_NAME}`;
l.IS_ADMIN = l.IS_ADMIN == "Y";
l.surveys = await db.getSurveysByEmail(l.EMAIL);
}

return res.json({ data: list });
Expand All @@ -33,7 +29,7 @@ userRouter.post("/", async (req: Request, res: Response) => {
return res.json({ data: { error: [{ text: "User already exists", variant: "error" }] } });
}

await db.create({
/* await db.create({
EMAIL: user.email,
USER_ID: "SUB_MISSING",
STATUS: UserStatus.ACTIVE,
Expand All @@ -42,7 +38,7 @@ userRouter.post("/", async (req: Request, res: Response) => {
IS_ADMIN: "N",
ROLE: "",
CREATE_DATE: new Date(),
});
}); */
}
return res.json({});
});
Expand All @@ -57,7 +53,7 @@ userRouter.put(

let existing = await db.getByEmail(email);

if (existing) {
/* if (existing) {
existing.STATUS = STATUS;
existing.IS_ADMIN = IS_ADMIN ? "Y" : "N";
existing.ROLE = IS_ADMIN ? null : ROLE;
Expand All @@ -78,18 +74,18 @@ userRouter.put(
messages: [{ variant: "success", text: "User saved" }],
});
}

*/
res.status(404).send();
}
);

userRouter.post("/search-directory", async (req: Request, res: Response) => {
let { terms } = req.body;

/* let directoryService = new DirectoryService();
/* let directoryService = new DirectoryService();
await directoryService.connect();
let results = await directoryService.search(terms); */
const results = ["ignore"]
const results = ["ignore"];

return res.json({ data: results });
});
33 changes: 9 additions & 24 deletions api/src/services/user-service.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,31 @@
import { DB_SCHEMA, DB_USER_TABLE } from "../config";
import { DB_SCHEMA } from "../config";
import { User, User_Create, User_Update } from "../data/models";
import { db } from "../data";

export class UserService {
async getAll(): Promise<User[]> {
return db.withSchema(DB_SCHEMA).from(DB_USER_TABLE).orderBy(["FIRST_NAME", "LAST_NAME"]);
return db.withSchema(DB_SCHEMA).from("users").orderBy(["first_name", "last_name"]);
}

async getBySub(USER_ID: string): Promise<User | undefined> {
let user = await db<User>(DB_USER_TABLE).withSchema(DB_SCHEMA).where({ USER_ID }).first();
async getBySub(auth_subject: string): Promise<User | undefined> {
let user = await db<User>("users").withSchema(DB_SCHEMA).where({ auth_subject }).first();
return user;
}

async getByEmail(EMAIL: string): Promise<User | undefined> {
if (EMAIL) {
let user = await db<User>(DB_USER_TABLE).withSchema(DB_SCHEMA).where({ EMAIL }).first();
async getByEmail(email: string): Promise<User | undefined> {
if (email) {
let user = await db<User>("users").withSchema(DB_SCHEMA).where({ email }).first();
return user;
}

return undefined;
}

async create(item: User_Create): Promise<any> {
return db(DB_USER_TABLE).withSchema(DB_SCHEMA).insert(item);
return db("users").withSchema(DB_SCHEMA).insert(item);
}

async update(EMAIL: string, item: User_Update): Promise<User> {
return db(DB_USER_TABLE).withSchema(DB_SCHEMA).where({ EMAIL }).update(item);
}

async getSurveysByEmail(EMAIL: string) {
let lines = await db("SURVEY_USER").withSchema(DB_SCHEMA).where({ EMAIL }).select("SID");
return lines.map((s) => s.SID);
}

async clearSurveysByEmail(EMAIL: string) {
return db("SURVEY_USER").withSchema(DB_SCHEMA).where({ EMAIL }).delete();
}

async setSurveysByEmail(EMAIL: string, surveys: number[]) {
for (let SID of surveys) {
await db("SURVEY_USER").withSchema(DB_SCHEMA).insert({ EMAIL, SID });
}
return db("users").withSchema(DB_SCHEMA).where({ EMAIL }).update(item);
}
}
11 changes: 10 additions & 1 deletion web/src/assets/yk-style.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ p {
}

* {
font-family: Montserrat, Helvetica, Arial, sans-serif;
font-family: Montserrat, Helvetica, Arial, sans-serif !important;
}

h1 {
Expand All @@ -24,6 +24,11 @@ h3 {

a {
text-decoration: none;
color: #0097a9;
}

.title-link {
color: #323232;
}

.v-main .v-btn,
Expand Down Expand Up @@ -148,3 +153,7 @@ ul.v-breadcrumbs {
.markdown li {
margin-left: 20px;
}

.bg-sun {
background-color: #f2a90055;
}
5 changes: 4 additions & 1 deletion web/src/components/incident/CreateButton.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<template>
<v-btn color="primary" to="/report-an-incident">Report an Incident</v-btn>
<v-btn color="success" to="/report-an-incident" size="large">
<v-icon class="mr-4">mdi-clipboard-alert-outline</v-icon>
Report an Incident</v-btn
>
</template>

<script setup lang="ts"></script>
36 changes: 36 additions & 0 deletions web/src/components/incident/CreateCompletePage.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<template>
<h1 class="text-h4">Report an Incident - Complete</h1>
<!-- <p class="text-body-2">
Personal information is collected under the Workers' Safety and Compensation Act, Section #, for the purposes of
Incident investigation and corrective action. For further information, contant the Director of Health, Safety &
Wellbeing at 867-332-5974
</p> -->

<v-form class="mt-6">
<section>
<v-card class="default">
<v-card-item class="py-4 px-6 mb-2 bg-sun">
<h4 class="text-h6">Thank you!</h4>
</v-card-item>
<v-card-text>
<p class="text-body-1 mb-5 mt-5">
Your submission has been received and you will recieve email notifications regarding the status of this
submission.
</p>
<p class="text-body-1 mb-5 mt-5">At any time, you can also view your previously submitted reports on this site.</p>

<div class="d-flex">
<v-btn color="primary" to="/" class="mr-5">Go back home</v-btn>
<v-btn color="warning" to="/report-an-incident" variant="tonal">Submit another report</v-btn>
</div>
</v-card-text>
</v-card>
</section>
</v-form>
</template>

<script setup>
import { ref } from "vue";
const eventType = ref(null);
</script>
Loading

0 comments on commit 7433af2

Please sign in to comment.