Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: CI

on:
push:
branches: [ main ]
branches: [main]
pull_request:

jobs:
Expand Down Expand Up @@ -40,4 +40,4 @@ jobs:
run: npm ci

- name: Build frontend & backend
run: npx nx build backend frontend
run: npx nx build backend frontend
88 changes: 44 additions & 44 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL Advanced"
name: 'CodeQL Advanced'

on:
push:
branches: [ "main" ]
branches: ['main']
pull_request:
branches: [ "main" ]
branches: ['main']
schedule:
- cron: '43 6 * * 6'

Expand Down Expand Up @@ -43,10 +43,10 @@ jobs:
fail-fast: false
matrix:
include:
- language: actions
build-mode: none
- language: javascript-typescript
build-mode: none
- language: actions
build-mode: none
- language: javascript-typescript
build-mode: none
# CodeQL supports the following values keywords for 'language': 'actions', 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift'
# Use `c-cpp` to analyze code written in C, C++ or both
# Use 'java-kotlin' to analyze code written in Java, Kotlin or both
Expand All @@ -56,45 +56,45 @@ jobs:
# If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how
# your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Checkout repository
uses: actions/checkout@v4

# Add any setup steps before running the `github/codeql-action/init` action.
# This includes steps like installing compilers or runtimes (`actions/setup-node`
# or others). This is typically only required for manual builds.
# - name: Setup runtime (example)
# uses: actions/setup-example@v1
# Add any setup steps before running the `github/codeql-action/init` action.
# This includes steps like installing compilers or runtimes (`actions/setup-node`
# or others). This is typically only required for manual builds.
# - name: Setup runtime (example)
# uses: actions/setup-example@v1

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
build-mode: ${{ matrix.build-mode }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
build-mode: ${{ matrix.build-mode }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality

# If the analyze step fails for one of the languages you are analyzing with
# "We were unable to automatically build your code", modify the matrix above
# to set the build mode to "manual" for that language. Then modify this step
# to build your code.
# ā„¹ļø Command-line programs to run using the OS shell.
# šŸ“š See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
- if: matrix.build-mode == 'manual'
shell: bash
run: |
echo 'If you are using a "manual" build mode for one or more of the' \
'languages you are analyzing, replace this with the commands to build' \
'your code, for example:'
echo ' make bootstrap'
echo ' make release'
exit 1
# If the analyze step fails for one of the languages you are analyzing with
# "We were unable to automatically build your code", modify the matrix above
# to set the build mode to "manual" for that language. Then modify this step
# to build your code.
# ā„¹ļø Command-line programs to run using the OS shell.
# šŸ“š See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
- if: matrix.build-mode == 'manual'
shell: bash
run: |
echo 'If you are using a "manual" build mode for one or more of the' \
'languages you are analyzing, replace this with the commands to build' \
'your code, for example:'
echo ' make bootstrap'
echo ' make release'
exit 1

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: '/language:${{matrix.language}}'
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
"printWidth": 100,
"trailingComma": "none",
"arrowParens": "avoid"
}
}
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ npm run dev

Deploy the application swiftly using Docker Compose. šŸš€ Ensure Docker is running.

> [!IMPORTANT]
> [!IMPORTANT]
> Before launching, configure your environment variables. The backend service needs an `apps/backend/.env.local` file (copy `apps/backend/.env` if needed). The `JWT_SECRET` is crucial. ✨

Run this from the project root:
Expand All @@ -76,6 +76,7 @@ docker-compose up -d
This builds and starts frontend and backend services in detached mode.

Access:

- **Frontend**: `http://localhost:4200` šŸ–„ļø
- **Backend API**: `http://localhost:3333` āš™ļø

Expand Down Expand Up @@ -112,5 +113,4 @@ mtes/

This project is licensed under the GPL-3.0 License. It utilizes a similar tech stack and codebase inspired by [FIRSTIsrael/lems](https://github.com/FIRSTIsrael/lems); šŸ™ thank you for making this possible! šŸš€


***Made with ā¤ļø by [@TheCommandCat](https://github.com/TheCommandCat)***
**_Made with ā¤ļø by [@TheCommandCat](https://github.com/TheCommandCat)_**
60 changes: 48 additions & 12 deletions apps/backend/src/lib/schedule/cleaner.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,54 @@
import * as db from '@mtes/database';
import { ObjectId } from 'mongodb';

export const cleanDivisionData = async () => {
if (!(await db.deleteElectionEvent())) throw new Error('Could not delete event!');
if (!(await db.deleteUsers(
{ isAdmin: { $ne: true } }
)).acknowledged) throw new Error('Could not delete users!');
if (!(await db.deleteElectionState()).acknowledged) {
export const cleanDivisionData = async (eventId: ObjectId) => {
if (!(await db.deleteElectionEvent(eventId))) throw new Error('Could not delete event!');
if (!(await db.deleteUsers({ _id: eventId })).acknowledged)
throw new Error('Could not delete users!');
if (!(await db.deleteElectionState(eventId)).acknowledged) {
throw new Error('Could not delete Election state!');
}

if (!(await db.deleteMembers({})).acknowledged) throw new Error('Could not delete members!');
if (!(await db.deleteContestants()).acknowledged) throw new Error('Could not delete contestant!');
if (!(await db.deleteRounds()).acknowledged) throw new Error('Could not delete rounds!');
if (!(await db.deleteVotes()).acknowledged) throw new Error('Could not delete votes!');
if (!(await db.deleteVotingStatuses()).acknowledged) throw new Error('Could not delete voting statuses!');
if (!(await db.deleteCities()).acknowledged) throw new Error('Could not delete cities!');
if (
!(
await db.deleteMembers({
_id: eventId
})
).acknowledged
)
throw new Error('Could not delete members!');
if (
!(
await db.deleteContestants({
_id: eventId
})
).acknowledged
)
throw new Error('Could not delete contestant!');
if (!(await db.deleteRounds({ eventId })).acknowledged)
throw new Error('Could not delete rounds!');
if (
!(
await db.deleteVotes({
_id: eventId
})
).acknowledged
)
throw new Error('Could not delete votes!');
if (
!(
await db.deleteVotingStatuses({
_id: eventId
})
).acknowledged
)
throw new Error('Could not delete voting statuses!');
if (
!(
await db.deleteCities({
_id: eventId
})
).acknowledged
)
throw new Error('Could not delete cities!');
};
11 changes: 7 additions & 4 deletions apps/backend/src/lib/schedule/voting-stands-users.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { User } from '@mtes/types';
import { ObjectId } from 'mongodb';

const randomString = (length: number) => {
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
Expand All @@ -9,10 +10,11 @@ const randomString = (length: number) => {
return result;
};

export const CreateVotingStandUsers = (numOfStands: number): User[] => {
const users = [];
export const CreateVotingStandUsers = (numOfStands: number, eventId: ObjectId): User[] => {
const users: User[] = [];

users.push({
eventId: eventId,
isAdmin: false,
role: 'election-manager',
password: randomString(4),
Expand All @@ -21,6 +23,7 @@ export const CreateVotingStandUsers = (numOfStands: number): User[] => {

for (let i = 1; i <= numOfStands; i++) {
users.push({
eventId: eventId,
isAdmin: false,
role: 'voting-stand',
password: randomString(4),
Expand All @@ -33,12 +36,12 @@ export const CreateVotingStandUsers = (numOfStands: number): User[] => {
}

users.push({
eventId: eventId,
isAdmin: false,
role: 'audience-display',
password: randomString(4),
lastPasswordSetDate: new Date(),
lastPasswordSetDate: new Date()
});


return users;
};
7 changes: 2 additions & 5 deletions apps/backend/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ const port = process.env.PORT ? Number(process.env.PORT) : 3333;
const app = express();
const server = http.createServer(app);
const corsOptions = {
origin: [
/localhost:\d+$/,
/\.thecommandcat\.me$/
],
origin: [/localhost:\d+$/, /\.thecommandcat\.me$/],
credentials: true
};
const io = new Server(server, { cors: corsOptions });
Expand Down Expand Up @@ -51,4 +48,4 @@ server.listen(port, () => {
console.log(`āœ… Server started on port ${port}.`);
});

server.on('error', console.error);
server.on('error', console.error);
2 changes: 1 addition & 1 deletion apps/backend/src/middlewares/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const authMiddleware = async (req: Request, res: Response, next: NextFunc
if (user) {
delete user.password;
req.user = user;
return next();
return next();
}
} catch (err) {
//Invalid token
Expand Down
Loading