Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
66aa780
feat: bump fe deps
SebassNoob May 4, 2024
70a9c5e
feat: bump be deps
SebassNoob May 4, 2024
bc78f03
chore: remove unused imports, console log from tests
SebassNoob May 4, 2024
8d6a7e3
chore: bump runtimes
SebassNoob May 4, 2024
6cd3773
feat: add service hours exports
SebassNoob May 3, 2024
c225852
feat: WIP frontend
SebassNoob May 6, 2024
7b0fe6d
feat: fix up functionality, styles
SebassNoob May 6, 2024
82d1437
[autofix.ci] apply automated fixes
autofix-ci[bot] May 6, 2024
f741681
fix: fix sonar issues
SebassNoob May 6, 2024
e6cebc7
[autofix.ci] apply automated fixes
autofix-ci[bot] May 6, 2024
b9f3e68
fix: rm unused method
SebassNoob May 6, 2024
05eebfa
chore: allow images to be pushed
SebassNoob Jun 17, 2024
820c736
fix: increase timeout for scheduler install
SebassNoob Jun 17, 2024
f7372a9
feat: bump app version
SebassNoob Jun 17, 2024
436975c
:bug: Fix use of let export in email handler
AJR07 Aug 21, 2024
0b8982e
[autofix.ci] apply automated fixes
autofix-ci[bot] Aug 21, 2024
a1fb01e
:bug: Merge run instruction into one
AJR07 Aug 21, 2024
b821a4a
:sparkles: Combine a few more run instructions
AJR07 Aug 21, 2024
e560d03
:bug: Make button focusable
AJR07 Aug 23, 2024
24e0dec
:bug: Add role as button and make it focusable
AJR07 Aug 23, 2024
adfeff5
:bug: Sort some package names alphabetically
AJR07 Aug 23, 2024
4785887
:art: :bug: Refractor a bunch of stuff
AJR07 Aug 23, 2024
8b48610
[autofix.ci] apply automated fixes
autofix-ci[bot] Aug 23, 2024
24bd3de
fix: typo in minio client url
SebassNoob Aug 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/autofix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Setup bun
uses: oven-sh/setup-bun@v1
with:
bun-version: 1.1.3
bun-version: 1.1.7

- name: Install dependencies (backend)
run: cd interapp-backend && bun install
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Setup bun
uses: oven-sh/setup-bun@v1
with:
bun-version: 1.1.3
bun-version: 1.1.7

- name: Install dependencies
run: cd interapp-backend && bun install
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,7 @@ run:
$(DC_CMD) up -d
down:
$(DC_CMD) -v down

# push docker images to the registry
push:
docker compose -f docker-compose.prod.yml push
4 changes: 4 additions & 0 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ services:

scheduler:
container_name: interapp-scheduler
image: sebassnoob/interapp-scheduler:latest
restart: on-failure
build:
context: ./interapp-backend
Expand Down Expand Up @@ -81,6 +82,7 @@ services:

backend:
container_name: interapp-backend
image: sebassnoob/interapp-backend:latest
restart: always
build:
context: ./interapp-backend
Expand All @@ -101,6 +103,7 @@ services:

frontend:
container_name: interapp-frontend
image: sebassnoob/interapp-frontend:latest
build:
context: ./interapp-frontend
dockerfile: prod.Dockerfile
Expand All @@ -118,6 +121,7 @@ services:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove trailing spaces to maintain clean and consistent formatting.

-    image: sebassnoob/interapp-nginx:latest    
+    image: sebassnoob/interapp-nginx:latest

Committable suggestion was skipped due to low confidence.

Tools
yamllint

[error] 121-121: trailing spaces (trailing-spaces)

nginx:
container_name: interapp-nginx
image: sebassnoob/interapp-nginx:latest
build:
context: ./nginx
dockerfile: prod.Dockerfile
Expand Down
46 changes: 17 additions & 29 deletions interapp-backend/api/email_handler/index.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import { Transporter, createTransport } from 'nodemailer';
import hbs from 'nodemailer-express-handlebars';

let transporter: Transporter;
try {
transporter = createTransport({
service: 'gmail',
host: 'smtp.gmail.com',
port: 587,
secure: false,
auth: {
user: process.env.EMAIL_USER as string,
pass: process.env.EMAIL_PASSWORD as string,
},
});
} catch (err) {
console.error(err);
process.exit(1);
}
const transporter: Transporter = (() => {
try {
return createTransport({
service: 'gmail',
host: 'smtp.gmail.com',
port: 587,
secure: false,
auth: {
user: process.env.EMAIL_USER as string,
pass: process.env.EMAIL_PASSWORD as string,
},
});
} catch (err) {
console.error(err);
process.exit(1);
}
})();

const handlebarsOptions: hbs.NodemailerExpressHandlebarsOptions = {
viewEngine: {
Expand All @@ -30,16 +31,3 @@ const handlebarsOptions: hbs.NodemailerExpressHandlebarsOptions = {
transporter.use('compile', hbs(handlebarsOptions));

export default transporter;

/*
await transporter.sendMail({
from: {
name: 'hi',
address: process.env.EMAIL_USER as string,
}, // sender address
to: ['sebastian.ong@hotmail.com'], // list of receivers
subject: "Hello ✔", // Subject line
text: "Hello world?", // plain text body
html: "<b>Hello world?</b>", // html body
});
*/
2 changes: 1 addition & 1 deletion interapp-backend/api/models/exports/exports_attendance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
import { BaseExportsModel } from './exports_base';
import { ServiceSession, type AttendanceStatus } from '@db/entities';
import { HTTPErrors } from '@utils/errors';
import { WorkSheet } from 'node-xlsx';
import { type WorkSheet } from 'node-xlsx';
import appDataSource from '@utils/init_datasource';

@staticImplements<ExportsModelImpl>()
Expand Down
47 changes: 40 additions & 7 deletions interapp-backend/api/models/exports/exports_service_hours.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,48 @@
import {
AttendanceExportsResult,
AttendanceExportsXLSX,
AttendanceQueryExportsConditions,
type ServiceHoursExportResult,
type ServiceHoursExportsXLSX,
type ServiceHoursQueryExportsConditions,
ExportsModelImpl,
staticImplements,
} from './types';
import { BaseExportsModel } from './exports_base';
import { ServiceSession, type AttendanceStatus } from '@db/entities';
import { User } from '@db/entities';
import { HTTPErrors } from '@utils/errors';
import { WorkSheet } from 'node-xlsx';
import appDataSource from '@utils/init_datasource';

// @staticImplements<ExportsModelImpl>()
export class ServiceHoursExportsModel extends BaseExportsModel {}
@staticImplements<ExportsModelImpl>()
export class ServiceHoursExportsModel extends BaseExportsModel {
public static async queryExports({ type, order }: ServiceHoursQueryExportsConditions) {
const result: ServiceHoursExportResult[] = await appDataSource.manager
.createQueryBuilder()
.select(['user.user_id', 'user.username', 'user.service_hours'])
.from(User, 'user')
.orderBy(`user.${type}`, order)
.getMany();
return result;
}
public static async formatXLSX(conds: ServiceHoursQueryExportsConditions) {
const ret = await this.queryExports(conds);

if (ret.length === 0) throw HTTPErrors.RESOURCE_NOT_FOUND;

const data: ServiceHoursExportsXLSX = [
['user_id', 'username', 'service_hours'],
...ret.map(
(r) => [r.user_id, r.username, r.service_hours] satisfies ServiceHoursExportsXLSX[1],
),
];

const sheetOptions = this.getSheetOptions(data);

return { name: 'service hours', data, options: sheetOptions };
}
public static async packXLSX(
type: ServiceHoursQueryExportsConditions['type'],
order: ServiceHoursQueryExportsConditions['order'],
) {
const worksheet = await this.formatXLSX({ type, order });

return this.constructXLSX(worksheet);
}
}
21 changes: 19 additions & 2 deletions interapp-backend/api/models/exports/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { AttendanceStatus } from '@db/entities';
import { type WorkSheet } from 'node-xlsx';

export interface ExportsModelImpl {
queryExports(conds: unknown): Promise<unknown[]>;
formatXLSX(conds: unknown): Promise<unknown>;
packXLSX(ids: number[], start_date?: string, end_date?: string): Promise<Buffer>;
formatXLSX(conds: unknown): Promise<WorkSheet>;
packXLSX(...params: unknown[]): Promise<Buffer>;
}

// class decorator that asserts that a class implements an interface statically
Expand Down Expand Up @@ -48,3 +49,19 @@ export type AttendanceQueryExportsConditions = {
end_date?: never;
}
);

export type ServiceHoursExportResult = {
username: string;
user_id: number;
service_hours: number;
};

export type ServiceHoursExportsXLSX = [
['user_id', 'username', 'service_hours'],
...[number, string, number][],
];

export type ServiceHoursQueryExportsConditions = {
type: 'user_id' | 'username' | 'service_hours';
order: 'ASC' | 'DESC';
};
24 changes: 20 additions & 4 deletions interapp-backend/api/routes/endpoints/exports/exports.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AttendanceExportsModel } from '@models/exports';
import { AttendanceExportsModel, ServiceHoursExportsModel } from '@models/exports';
import { z } from 'zod';
import { validateRequiredFields, verifyJWT, verifyRequiredPermission } from '@routes/middleware';
import { ExportsFields } from './validation';
import { AttendanceExportsFields, ServiceHoursExportsFields } from './validation';
import { Router } from 'express';
import { Permissions } from '@utils/permissions';

Expand All @@ -11,11 +11,11 @@ const xlsxMime = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sh

exportsRouter.get(
'/',
validateRequiredFields(ExportsFields),
validateRequiredFields(AttendanceExportsFields),
verifyJWT,
verifyRequiredPermission(Permissions.ATTENDANCE_MANAGER),
async (req, res) => {
const query = req.query as unknown as z.infer<typeof ExportsFields>;
const query = req.query as unknown as z.infer<typeof AttendanceExportsFields>;

const exports = await AttendanceExportsModel.packXLSX(
query.id,
Expand All @@ -29,3 +29,19 @@ exportsRouter.get(
res.status(200).send(exports);
},
);
exportsRouter.get(
'/service_hours',
validateRequiredFields(ServiceHoursExportsFields),
verifyJWT,
verifyRequiredPermission(Permissions.ATTENDANCE_MANAGER),
async (req, res) => {
const query = req.query as unknown as z.infer<typeof ServiceHoursExportsFields>;

const exports = await ServiceHoursExportsModel.packXLSX(query.type, query.order);

res.setHeader('Content-Type', xlsxMime);
res.setHeader('Content-Disposition', 'attachment; filename=output.xlsx');
res.type(xlsxMime);
res.status(200).send(exports);
},
);
9 changes: 8 additions & 1 deletion interapp-backend/api/routes/endpoints/exports/validation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { z } from 'zod';

export const ExportsFields = z
export const AttendanceExportsFields = z
.object({
id: z.array(z.coerce.number()).or(z.coerce.number()),
start_date: z.string().optional(),
Expand Down Expand Up @@ -52,3 +52,10 @@ export const ExportsFields = z
...data,
id: Array.isArray(data.id) ? data.id : [data.id],
}));

export const ServiceHoursExportsFields = z
.object({
type: z.enum(['user_id', 'username', 'service_hours']),
order: z.enum(['ASC', 'DESC']),
})
.transform((data) => data);
2 changes: 1 addition & 1 deletion interapp-backend/api/routes/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function validateRequiredFields<T extends z.ZodType<ReqBody | ReqQuery>>(
export async function verifyJWT(req: Request, res: Response, next: NextFunction) {
const authHeader = req.headers.authorization;

if (!authHeader || !authHeader.startsWith('Bearer ')) {
if (!authHeader?.startsWith('Bearer ')) {
throw new HTTPError(
'Missing JWT',
'You must provide a JWT token in the Authorization header',
Expand Down
Binary file modified interapp-backend/bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion interapp-backend/dev.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM oven/bun:1.1.3
FROM oven/bun:1.1.7
WORKDIR /app

COPY . .
Expand Down
8 changes: 4 additions & 4 deletions interapp-backend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "interapp-backend",
"version": "0.4.1",
"version": "0.5.0",
"module": "index.ts",
"type": "module",
"scripts": {
Expand Down Expand Up @@ -43,7 +43,7 @@
"dependencies": {
"cookie-parser": "^1.4.6",
"cors": "^2.8.5",
"express": "^4.18.2",
"express": "^4.19.2",
"express-async-errors": "^3.1.1",
"express-rate-limit": "^7.1.4",
"jose": "^5.1.1",
Expand All @@ -56,7 +56,7 @@
"pg": "^8.11.3",
"redis": "^4.6.10",
"swagger-ui-express": "^5.0.0",
"typeorm": "^0.3.17",
"zod": "^3.22.4"
"typeorm": "^0.3.19",
"zod": "^3.23.6"
}
}
2 changes: 1 addition & 1 deletion interapp-backend/prod.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM oven/bun:1.1.3
FROM oven/bun:1.1.7
WORKDIR /app

COPY . .
Expand Down
21 changes: 10 additions & 11 deletions interapp-backend/scheduler/dev.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
FROM oven/bun:1.1.3
FROM oven/bun:1.1.7
WORKDIR /app

COPY . .

RUN bun install --frozen-lockfile
RUN bun install --frozen-lockfile && \
# install curl, lsb-release and gnupg
apt-get update && apt-get install -y curl gnupg lsb-release && apt-get clean && \
Comment on lines +6 to +8
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consolidate installation steps.

The installation of curl, gnupg, and lsb-release has been consolidated. Consider using --no-install-recommends to avoid unnecessary packages.

apt-get update && apt-get install -y --no-install-recommends curl gnupg lsb-release && apt-get clean && \
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
RUN bun install --frozen-lockfile && \
# install curl, lsb-release and gnupg
apt-get update && apt-get install -y curl gnupg lsb-release && apt-get clean && \
RUN bun install --frozen-lockfile && \
# install curl, lsb-release and gnupg
apt-get update && apt-get install -y --no-install-recommends curl gnupg lsb-release && apt-get clean && \


# install curl, lsb-release and gnupg
RUN apt-get update && apt-get install -y curl lsb-release gnupg && apt-get clean
# add postgresql repository
curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - && \
echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" | tee /etc/apt/sources.list.d/pgdg.list && \

# add postgresql repository
RUN curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" | tee /etc/apt/sources.list.d/pgdg.list
# update and install postgresql-client-16, tzdata
apt-get update && apt-get install -y --fix-missing postgresql-client-16 tzdata && apt-get clean && \

# update and install postgresql-client-16, tzdata
RUN apt-get update && apt-get install -y --fix-missing postgresql-client-16 tzdata && apt-get clean

RUN ARCH=$(case "$(uname -m)" in "x86_64") echo "amd64";; "ppc64le") echo "ppc64le";; *) echo "Unsupported architecture"; exit 1;; esac) && \
ARCH=$(case "$(uname -m)" in "x86_64") echo "amd64";; "ppc64le") echo "ppc64le";; *) echo "Unsupported architecture"; exit 1;; esac) && \
DOWNLOAD_URL=$(case "$ARCH" in "amd64") echo "https://dl.min.io/client/mc/release/linux-amd64/mc";; "ppc64le") echo "https://dl.min.io/client/mc/release/linux-ppc64le/mc";; *) echo "Unsupported architecture"; exit 1;; esac) && \
# Install wget to download MinIO client
apt-get update && apt-get install -y wget && \
Expand Down
23 changes: 13 additions & 10 deletions interapp-backend/scheduler/prod.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
FROM oven/bun:1.1.3
FROM oven/bun:1.1.7
WORKDIR /app

COPY . .

RUN bun install --production --frozen-lockfile
RUN bun install --production --frozen-lockfile && \

# install curl, lsb-release and gnupg
RUN apt-get update && apt-get install -y curl lsb-release gnupg && apt-get clean
# install curl, lsb-release and gnupg
apt-get update && apt-get install -y curl gnupg lsb-release && apt-get clean && \

# add postgresql repository
RUN curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" | tee /etc/apt/sources.list.d/pgdg.list
# add postgresql repository
curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - && \
echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" | tee /etc/apt/sources.list.d/pgdg.list && \

# update and install postgresql-client-16, tzdata
RUN apt-get update && apt-get install -y --fix-missing postgresql-client-16 tzdata && apt-get clean
# update and install postgresql-client-16, tzdata
# set timeout to 8 minutes
echo 'Acquire::http::Timeout "480";' > /etc/apt/apt.conf.d/99timeout && \
echo 'Acquire::ftp::Timeout "480";' >> /etc/apt/apt.conf.d/99timeout && \
apt-get update && apt-get install -y --fix-missing postgresql-client-16 tzdata && apt-get clean && \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pin package versions and use --no-install-recommends.

Consider pinning package versions and using --no-install-recommends to avoid unnecessary packages and ensure consistent builds.

apt-get install -y --no-install-recommends --fix-missing postgresql-client-16=16.0 tzdata=2023a && apt-get clean && \
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
apt-get update && apt-get install -y --fix-missing postgresql-client-16 tzdata && apt-get clean && \
apt-get update && apt-get install -y --no-install-recommends --fix-missing postgresql-client-16=16.0 tzdata=2023a && apt-get clean && \


RUN ARCH=$(case "$(uname -m)" in "x86_64") echo "amd64";; "ppc64le") echo "ppc64le";; *) echo "Unsupported architecture"; exit 1;; esac) && \
ARCH=$(case "$(uname -m)" in "x86_64") echo "amd64";; "ppc64le") echo "ppc64le";; *) echo "Unsupported architecture"; exit 1;; esac) && \
DOWNLOAD_URL=$(case "$ARCH" in "amd64") echo "https://dl.min.io/client/mc/release/linux-amd64/mc";; "ppc64le") echo "https://dl.min.io/client/mc/release/linux-ppc64le/mc";; *) echo "Unsupported architecture"; exit 1;; esac) && \
# Install wget to download MinIO client
apt-get update && apt-get install -y wget && \
Expand Down
2 changes: 1 addition & 1 deletion interapp-backend/tests/config/test.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM oven/bun:1.1.3
FROM oven/bun:1.1.7
WORKDIR /app

COPY . .
Expand Down
Loading