Compare commits
18 Commits
DIscussion
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| b4ff7d4686 | |||
| 171e3b3137 | |||
| dd2ac19e4a | |||
| 18ba9b576c | |||
| 6c85677e1b | |||
| adb5e3e137 | |||
| 1749c3e617 | |||
| 52ee36be44 | |||
| 0cc327a9c4 | |||
| ef3cbbf370 | |||
| 209d0cdf0f | |||
| ab6c6f9acd | |||
| 95200b7970 | |||
| ae2c4d27bc | |||
| adc9da6a40 | |||
| a988545dda | |||
| 54dcb9d389 | |||
| c34f8beea9 |
@@ -1,53 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
var dbm;
|
|
||||||
var type;
|
|
||||||
var seed;
|
|
||||||
var fs = require('fs');
|
|
||||||
var path = require('path');
|
|
||||||
var Promise;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* We receive the dbmigrate dependency from dbmigrate initially.
|
|
||||||
* This enables us to not have to rely on NODE_PATH.
|
|
||||||
*/
|
|
||||||
exports.setup = function(options, seedLink) {
|
|
||||||
dbm = options.dbmigrate;
|
|
||||||
type = dbm.dataType;
|
|
||||||
seed = seedLink;
|
|
||||||
Promise = options.Promise;
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.up = function(db) {
|
|
||||||
var filePath = path.join(__dirname, 'sqls', '20260222232949-discussion-posts-up.sql');
|
|
||||||
return new Promise( function( resolve, reject ) {
|
|
||||||
fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){
|
|
||||||
if (err) return reject(err);
|
|
||||||
console.log('received data: ' + data);
|
|
||||||
|
|
||||||
resolve(data);
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.then(function(data) {
|
|
||||||
return db.runSql(data);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.down = function(db) {
|
|
||||||
var filePath = path.join(__dirname, 'sqls', '20260222232949-discussion-posts-down.sql');
|
|
||||||
return new Promise( function( resolve, reject ) {
|
|
||||||
fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){
|
|
||||||
if (err) return reject(err);
|
|
||||||
console.log('received data: ' + data);
|
|
||||||
|
|
||||||
resolve(data);
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.then(function(data) {
|
|
||||||
return db.runSql(data);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
exports._meta = {
|
|
||||||
"version": 1
|
|
||||||
};
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
/* Replace with your SQL commands */
|
|
||||||
DROP TABLE discussion_posts;
|
|
||||||
DROP TABLE discussion_comments;
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
/* Replace with your SQL commands */
|
|
||||||
CREATE TABLE discussion_posts (
|
|
||||||
id INT PRIMARY KEY AUTO_INCREMENT,
|
|
||||||
type VARCHAR(50) NOT NULL,
|
|
||||||
poster_id INT NOT NULL,
|
|
||||||
title VARCHAR(100) NOT NULL,
|
|
||||||
content JSON NOT NULL,
|
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
|
||||||
is_deleted BOOLEAN DEFAULT FALSE,
|
|
||||||
is_locked BOOLEAN DEFAULT FALSE,
|
|
||||||
is_open BOOLEAN GENERATED ALWAYS AS (
|
|
||||||
NOT is_deleted
|
|
||||||
AND NOT is_locked
|
|
||||||
) STORED,
|
|
||||||
FOREIGN KEY (poster_id) REFERENCES members(id) ON DELETE CASCADE
|
|
||||||
);
|
|
||||||
CREATE TABLE discussion_comments (
|
|
||||||
id INT PRIMARY KEY AUTO_INCREMENT,
|
|
||||||
post_id INT NOT NULL,
|
|
||||||
poster_id INT NOT NULL,
|
|
||||||
content TEXT NOT NULL,
|
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
|
||||||
is_deleted BOOLEAN DEFAULT FALSE,
|
|
||||||
FOREIGN KEY (post_id) REFERENCES discussion_posts(id) ON DELETE CASCADE,
|
|
||||||
FOREIGN KEY (poster_id) REFERENCES members(id) ON DELETE CASCADE
|
|
||||||
);
|
|
||||||
CREATE INDEX idx_discussion_posts_title ON discussion_posts(title);
|
|
||||||
CREATE INDEX idx_discussion_posts_type ON discussion_posts(type);
|
|
||||||
CREATE INDEX idx_discussion_posts_poster_id ON discussion_posts(poster_id);
|
|
||||||
CREATE INDEX idx_discussion_comments_post_id ON discussion_comments(post_id);
|
|
||||||
CREATE INDEX idx_discussion_comments_poster_id ON discussion_comments(poster_id);
|
|
||||||
CREATE INDEX idx_discussion_posts_is_open ON discussion_posts(is_open);
|
|
||||||
@@ -103,9 +103,7 @@ import { roles, memberRoles } from './routes/roles';
|
|||||||
import { courseRouter, eventRouter } from './routes/course';
|
import { courseRouter, eventRouter } from './routes/course';
|
||||||
import { calendarRouter } from './routes/calendar';
|
import { calendarRouter } from './routes/calendar';
|
||||||
import { docsRouter } from './routes/docs';
|
import { docsRouter } from './routes/docs';
|
||||||
import { units } from './routes/units';
|
import { memberUnits, units } from './routes/units';
|
||||||
import { modRequestRouter } from './routes/modRequest'
|
|
||||||
import { discussionRouter } from './routes/discussion';
|
|
||||||
|
|
||||||
app.use('/application', applicationRouter);
|
app.use('/application', applicationRouter);
|
||||||
app.use('/ranks', ranks);
|
app.use('/ranks', ranks);
|
||||||
@@ -120,9 +118,8 @@ app.use('/course', courseRouter)
|
|||||||
app.use('/courseEvent', eventRouter)
|
app.use('/courseEvent', eventRouter)
|
||||||
app.use('/calendar', calendarRouter)
|
app.use('/calendar', calendarRouter)
|
||||||
app.use('/units', units)
|
app.use('/units', units)
|
||||||
|
app.use('/memberUnits', memberUnits);
|
||||||
app.use('/docs', docsRouter)
|
app.use('/docs', docsRouter)
|
||||||
app.use('/mod-request', modRequestRouter)
|
|
||||||
app.use('/discussions', discussionRouter)
|
|
||||||
app.use('/', authRouter)
|
app.use('/', authRouter)
|
||||||
|
|
||||||
app.get('/ping', (req, res) => {
|
app.get('/ping', (req, res) => {
|
||||||
|
|||||||
@@ -396,11 +396,11 @@ VALUES(?, ?, ?, 1);`
|
|||||||
INNER JOIN members AS member ON member.id = app.poster_id
|
INNER JOIN members AS member ON member.id = app.poster_id
|
||||||
WHERE app.id = ?; `;
|
WHERE app.id = ?; `;
|
||||||
const comment = await conn.query(getSQL, [result.insertId])
|
const comment = await conn.query(getSQL, [result.insertId])
|
||||||
audit.record('application', 'comment_added', { actorId: user.id, targetId: appID }, { commentId: result.insertId });
|
audit.record('application', 'comment_added', { actorId: user.id, targetId: appID }, { commentId: Number(result.insertId) });
|
||||||
logger.info('app', "Admin application comment posted", {
|
logger.info('app', "Admin application comment posted", {
|
||||||
application: appID,
|
application: appID,
|
||||||
poster: user.id,
|
poster: user.id,
|
||||||
comment: result.insertId,
|
comment: Number(result.insertId),
|
||||||
})
|
})
|
||||||
|
|
||||||
res.status(201).json(comment[0]);
|
res.status(201).json(comment[0]);
|
||||||
|
|||||||
@@ -1,49 +0,0 @@
|
|||||||
const express = require('express');
|
|
||||||
const router = express.Router();
|
|
||||||
|
|
||||||
import { Request, Response } from 'express';
|
|
||||||
import { requireLogin, requireMemberState, requireRole } from '../middleware/auth';
|
|
||||||
import { logger } from '../services/logging/logger';
|
|
||||||
import { audit } from '../services/logging/auditLog';
|
|
||||||
import { MemberState } from '@app/shared/types/member';
|
|
||||||
import { createDiscussion, getAllDiscussions, getDiscussionById, getPostComments, postComment } from '../services/db/discussionService';
|
|
||||||
import { ModRequest } from '@app/shared/schemas/modRequest';
|
|
||||||
import { DiscussionComment } from '@app/shared/types/discussion';
|
|
||||||
|
|
||||||
router.use(requireLogin);
|
|
||||||
router.use(requireMemberState(MemberState.Member));
|
|
||||||
|
|
||||||
router.post('/comment', async (req: Request, res: Response) => {
|
|
||||||
try {
|
|
||||||
let comment = req.body as DiscussionComment;
|
|
||||||
|
|
||||||
if (!comment.content || comment.content.trim() === '') {
|
|
||||||
return res.status(400).json({ error: 'Comment content cannot be empty' });
|
|
||||||
}
|
|
||||||
|
|
||||||
let rowID = await postComment(comment, req.user.id);
|
|
||||||
audit.discussion('comment_posted', { actorId: req.user.id, targetId: rowID }, { parent: comment.post_id })
|
|
||||||
res.sendStatus(201);
|
|
||||||
} catch (error) {
|
|
||||||
logger.error('app', "Failed to post comments", error);
|
|
||||||
res.sendStatus(500);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
router.get('/:postId/comments', async (req: Request, res: Response) => {
|
|
||||||
try {
|
|
||||||
const postId = parseInt(req.params.postId);
|
|
||||||
const comments = await getPostComments(postId);
|
|
||||||
res.json(comments);
|
|
||||||
} catch (error) {
|
|
||||||
logger.error('app', "Failed to fetch comments", error);
|
|
||||||
res.sendStatus(500);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
router.delete('/comment/:id', async (req: Request, res: Response) => {
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
export const discussionRouter = router;
|
|
||||||
@@ -6,8 +6,8 @@ import pool from '../db';
|
|||||||
import { requireLogin, requireMemberState, requireRole } from '../middleware/auth';
|
import { requireLogin, requireMemberState, requireRole } from '../middleware/auth';
|
||||||
import { getUserActiveLOA } from '../services/db/loaService';
|
import { getUserActiveLOA } from '../services/db/loaService';
|
||||||
import { getAllMembersLite, getMemberSettings, getMembersFull, getMembersLite, getUserData, getUserState, setUserSettings, getFilteredMembers, setUserState, getLastNonSuspendedState } from '../services/db/memberService';
|
import { getAllMembersLite, getMemberSettings, getMembersFull, getMembersLite, getUserData, getUserState, setUserSettings, getFilteredMembers, setUserState, getLastNonSuspendedState } from '../services/db/memberService';
|
||||||
import { getUserRoles } from '../services/db/rolesService';
|
import { getUserRoles, stripUserRoles } from '../services/db/rolesService';
|
||||||
import { memberSettings, MemberState, myData } from '@app/shared/types/member';
|
import { memberSettings, MemberState, myData, UserCacheBustResult } from '@app/shared/types/member';
|
||||||
import { Discharge } from '@app/shared/schemas/dischargeSchema';
|
import { Discharge } from '@app/shared/schemas/dischargeSchema';
|
||||||
|
|
||||||
import { Performance } from 'perf_hooks';
|
import { Performance } from 'perf_hooks';
|
||||||
@@ -211,6 +211,32 @@ router.post('/full/bulk', async (req: Request, res: Response) => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
router.post('/cache/user/bust', [requireLogin, requireMemberState(MemberState.Member), requireRole('dev')], async (req: Request, res: Response) => {
|
||||||
|
try {
|
||||||
|
const clearedEntries = memberCache.Clear();
|
||||||
|
const payload: UserCacheBustResult = {
|
||||||
|
success: true,
|
||||||
|
clearedEntries,
|
||||||
|
bustedAt: new Date().toISOString(),
|
||||||
|
};
|
||||||
|
|
||||||
|
logger.info('app', 'User cache manually busted', {
|
||||||
|
actor: req.user.id,
|
||||||
|
clearedEntries,
|
||||||
|
});
|
||||||
|
|
||||||
|
return res.status(200).json(payload);
|
||||||
|
} catch (error) {
|
||||||
|
logger.error('app', 'Failed to bust user cache', {
|
||||||
|
caller: req.user?.id,
|
||||||
|
error: error instanceof Error ? error.message : String(error),
|
||||||
|
stack: error instanceof Error ? error.stack : undefined,
|
||||||
|
});
|
||||||
|
|
||||||
|
return res.status(500).json({ error: 'Failed to bust user cache' });
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
router.get('/:id', [requireLogin], async (req, res) => {
|
router.get('/:id', [requireLogin], async (req, res) => {
|
||||||
const userId = req.params.id;
|
const userId = req.params.id;
|
||||||
|
|
||||||
@@ -249,6 +275,7 @@ router.post('/discharge', [requireLogin, requireMemberState(MemberState.Member),
|
|||||||
|
|
||||||
var data: Discharge = req.body;
|
var data: Discharge = req.body;
|
||||||
setUserState(data.userID, MemberState.Discharged, "Member Discharged", author, con, data.reason);
|
setUserState(data.userID, MemberState.Discharged, "Member Discharged", author, con, data.reason);
|
||||||
|
stripUserRoles(data.userID, con);
|
||||||
cancelLatestRank(data.userID, con);
|
cancelLatestRank(data.userID, con);
|
||||||
cancelLatestUnit(data.userID, con);
|
cancelLatestUnit(data.userID, con);
|
||||||
con.commit();
|
con.commit();
|
||||||
|
|||||||
@@ -1,65 +0,0 @@
|
|||||||
const express = require('express');
|
|
||||||
const router = express.Router();
|
|
||||||
|
|
||||||
import { Request, Response } from 'express';
|
|
||||||
import { requireLogin, requireMemberState, requireRole } from '../middleware/auth';
|
|
||||||
import { logger } from '../services/logging/logger';
|
|
||||||
import { audit } from '../services/logging/auditLog';
|
|
||||||
import { MemberState } from '@app/shared/types/member';
|
|
||||||
import { createDiscussion, getAllDiscussions, getDiscussionById } from '../services/db/discussionService';
|
|
||||||
import { ModRequest } from '@app/shared/schemas/modRequest';
|
|
||||||
|
|
||||||
router.use(requireLogin);
|
|
||||||
router.use(requireMemberState(MemberState.Member));
|
|
||||||
|
|
||||||
router.get('/', async (req: Request, res: Response) => {
|
|
||||||
try {
|
|
||||||
const page = parseInt(req.query.page as string) || 1;
|
|
||||||
const pageSize = parseInt(req.query.pageSize as string) || 10;
|
|
||||||
const search = parseInt(req.query.search as string) || null;
|
|
||||||
|
|
||||||
const result = await getAllDiscussions<ModRequest>('mod_request', page, pageSize);
|
|
||||||
|
|
||||||
return res.json(result);
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error fetching mod requests:', error);
|
|
||||||
res.status(500).json({ error: 'Internal Server Error' });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// GET a single mod request by ID
|
|
||||||
router.get('/:id', async (req: Request, res: Response) => {
|
|
||||||
try {
|
|
||||||
const id = parseInt(req.params.id, 10);
|
|
||||||
if (isNaN(id)) {
|
|
||||||
return res.status(400).json({ error: 'Invalid ID' });
|
|
||||||
}
|
|
||||||
|
|
||||||
const discussion = await getDiscussionById<ModRequest>(id);
|
|
||||||
if (!discussion) {
|
|
||||||
return res.status(404).json({ error: 'Mod request not found' });
|
|
||||||
}
|
|
||||||
|
|
||||||
return res.json(discussion);
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error fetching mod request by id:', error);
|
|
||||||
res.status(500).json({ error: 'Internal Server Error' });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
router.post('/', async (req: Request, res: Response) => {
|
|
||||||
try {
|
|
||||||
let author = req.user.id;
|
|
||||||
let data = req.body as ModRequest;
|
|
||||||
|
|
||||||
let postID = await createDiscussion<ModRequest>('mod_request', author, data.mod_title, data);
|
|
||||||
logger.info('app', 'Mod request posted', {});
|
|
||||||
audit.discussion('created', { actorId: author, targetId: postID }, { type: "mod_request" });
|
|
||||||
return res.status(200).send(postID);
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error posting a mod request:', error);
|
|
||||||
res.status(500).json({ error: 'Internal Server Error' });
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
export const modRequestRouter = router;
|
|
||||||
@@ -1,10 +1,17 @@
|
|||||||
import express = require('express');
|
import express = require('express');
|
||||||
const unitsRouter = express.Router();
|
const unitsRouter = express.Router();
|
||||||
|
const memberUnitsRouter = express.Router();
|
||||||
|
|
||||||
|
import { Request, Response } from 'express';
|
||||||
|
|
||||||
import pool from '../db';
|
import pool from '../db';
|
||||||
import { requireLogin } from '../middleware/auth';
|
import { requireLogin, requireMemberState, requireRole } from '../middleware/auth';
|
||||||
import { logger } from '../services/logging/logger';
|
import { logger } from '../services/logging/logger';
|
||||||
import { Unit } from '@app/shared/types/units';
|
import { Unit } from '@app/shared/types/units';
|
||||||
|
import { MemberState } from '@app/shared/types/member';
|
||||||
|
import { assignNewUnit } from '../services/db/unitService';
|
||||||
|
import { audit } from '../services/logging/auditLog';
|
||||||
|
import { forceInsertMemberRank, insertMemberRank } from '../services/db/rankService';
|
||||||
|
|
||||||
unitsRouter.use(requireLogin);
|
unitsRouter.use(requireLogin);
|
||||||
|
|
||||||
@@ -26,4 +33,41 @@ unitsRouter.get('/', async (req, res) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
memberUnitsRouter.post('/admin', [requireMemberState(MemberState.Member), requireRole("17th Administrator")], async (req: Request, res: Response) => {
|
||||||
|
const memberId = Number(req.query.memberId);
|
||||||
|
const unitId = Number(req.query.unitId);
|
||||||
|
const rankId = Number(req.query.rankId);
|
||||||
|
const reason = req.query.reason as string;
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
if (!memberId || !unitId) {
|
||||||
|
return res.status(400).json({ error: 'memberId and unitId query parameters are required' });
|
||||||
|
}
|
||||||
|
|
||||||
|
await assignNewUnit(memberId, unitId, req.user.id, req.user.id, reason);
|
||||||
|
await forceInsertMemberRank(memberId, rankId, req.user.id, req.user.id, reason);
|
||||||
|
logger.info('app', 'Member force assigned unit', {
|
||||||
|
member: memberId,
|
||||||
|
unit: unitId,
|
||||||
|
rank: rankId,
|
||||||
|
caller: req.user.id,
|
||||||
|
});
|
||||||
|
audit.member('update_unit', { actorId: req.user.id, targetId: memberId }, { unit: unitId, rank: rankId, reason: reason });
|
||||||
|
|
||||||
|
res.sendStatus(200);
|
||||||
|
} catch (error) {
|
||||||
|
logger.error('app', 'Failed to force assign unit', {
|
||||||
|
member: memberId,
|
||||||
|
unit: unitId,
|
||||||
|
caller: req.user.id,
|
||||||
|
error: error instanceof Error ? error.message : String(error),
|
||||||
|
stack: error instanceof Error ? error.stack : undefined,
|
||||||
|
})
|
||||||
|
|
||||||
|
res.sendStatus(500);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
export const units = unitsRouter;
|
export const units = unitsRouter;
|
||||||
|
export const memberUnits = memberUnitsRouter;
|
||||||
10
api/src/services/cache/cache.ts
vendored
10
api/src/services/cache/cache.ts
vendored
@@ -16,4 +16,14 @@ export class CacheService<Key, Value> {
|
|||||||
public Invalidate(key: Key): boolean {
|
public Invalidate(key: Key): boolean {
|
||||||
return this.cacheMap.delete(key);
|
return this.cacheMap.delete(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Size(): number {
|
||||||
|
return this.cacheMap.size;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Clear(): number {
|
||||||
|
const priorSize = this.cacheMap.size;
|
||||||
|
this.cacheMap.clear();
|
||||||
|
return priorSize;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,150 +0,0 @@
|
|||||||
import { toDateTime } from "@app/shared/utils/time";
|
|
||||||
import pool from "../../db";
|
|
||||||
import { LOARequest, LOAType } from '@app/shared/types/loa'
|
|
||||||
import { PagedData } from '@app/shared/types/pagination'
|
|
||||||
import { DiscussionPost } from '@app/shared/types/discussion';
|
|
||||||
import { DiscussionComment } from '@app/shared/types/discussion';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieves all discussion posts with pagination and optional type filtering.
|
|
||||||
* @template T - The type of content stored in discussion posts
|
|
||||||
* @param {string} [type] - Optional type filter to retrieve only posts of a specific type
|
|
||||||
* @param {number} [page=1] - The page number for pagination (1-indexed)
|
|
||||||
* @param {number} [pageSize=10] - The number of posts per page
|
|
||||||
* @returns {Promise<PagedData<DiscussionPost<T>>>} A promise that resolves to paginated discussion posts with metadata
|
|
||||||
* @throws {Error} If the database query fails
|
|
||||||
*/
|
|
||||||
export async function getAllDiscussions<T>(type?: string, page = 1, pageSize = 10, search?: string): Promise<PagedData<DiscussionPost<T>>> {
|
|
||||||
const offset = (page - 1) * pageSize;
|
|
||||||
const params: any[] = [];
|
|
||||||
|
|
||||||
// Base query parts
|
|
||||||
let whereClause = "WHERE is_deleted = FALSE";
|
|
||||||
if (type) {
|
|
||||||
whereClause += " AND type = ?";
|
|
||||||
params.push(type);
|
|
||||||
}
|
|
||||||
|
|
||||||
const sql = `
|
|
||||||
SELECT
|
|
||||||
p.*,
|
|
||||||
m.name as poster_name
|
|
||||||
FROM discussion_posts AS p
|
|
||||||
LEFT JOIN members m ON p.poster_id = m.id
|
|
||||||
${whereClause}
|
|
||||||
ORDER BY
|
|
||||||
p.is_open DESC, -- Show active/unlocked threads first
|
|
||||||
p.created_at DESC -- Then show newest first
|
|
||||||
LIMIT ? OFFSET ?;
|
|
||||||
`;
|
|
||||||
|
|
||||||
// Add pagination params to the end
|
|
||||||
params.push(pageSize, offset);
|
|
||||||
|
|
||||||
// Execute queries
|
|
||||||
const posts: DiscussionPost<T>[] = await pool.query(sql, params) as DiscussionPost<T>[];
|
|
||||||
|
|
||||||
// Get count for the specific types
|
|
||||||
const countSql = `SELECT COUNT(*) as count FROM discussion_posts ${whereClause}`;
|
|
||||||
const countResult = await pool.query(countSql, type ? [type] : []);
|
|
||||||
const totalCount = Number(countResult[0].count);
|
|
||||||
|
|
||||||
const totalPages = Math.ceil(totalCount / pageSize);
|
|
||||||
|
|
||||||
return {
|
|
||||||
data: posts,
|
|
||||||
pagination: {
|
|
||||||
page,
|
|
||||||
pageSize,
|
|
||||||
total: totalCount,
|
|
||||||
totalPages
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new discussion post.
|
|
||||||
* @template T - The type of content for the discussion post
|
|
||||||
* @param {string} type - The type/category of the discussion post
|
|
||||||
* @param {number} authorID - The ID of the member creating the post
|
|
||||||
* @param {postTitle} string - The title of the discussion post
|
|
||||||
* @param {T} data - The content data to be stored in the post
|
|
||||||
* @returns {Promise<Number>} A promise that resolves to the ID of the newly created post
|
|
||||||
* @throws {Error} If the database insertion fails
|
|
||||||
*/
|
|
||||||
export async function createDiscussion<T>(type: string, authorID: number, postTitle: string, data: T): Promise<number> {
|
|
||||||
const sql = `
|
|
||||||
INSERT INTO discussion_posts (type, poster_id, title, content)
|
|
||||||
VALUES (?, ?, ?, ?)
|
|
||||||
`;
|
|
||||||
|
|
||||||
console.log(data);
|
|
||||||
const result = await pool.query(sql, [
|
|
||||||
type,
|
|
||||||
authorID,
|
|
||||||
postTitle,
|
|
||||||
JSON.stringify(data)
|
|
||||||
]);
|
|
||||||
|
|
||||||
console.log(result);
|
|
||||||
return Number(result.insertId);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieve a single discussion post by its ID.
|
|
||||||
* @template T - type of the content stored in the post (e.g. ModRequest)
|
|
||||||
* @param {number} id - The id of the discussion post to fetch
|
|
||||||
* @returns {Promise<DiscussionPost<T> | null>} The discussion post or null if not found
|
|
||||||
*/
|
|
||||||
export async function getDiscussionById<T>(id: number): Promise<DiscussionPost<T> | null> {
|
|
||||||
// Get the post
|
|
||||||
const postSql = `
|
|
||||||
SELECT
|
|
||||||
p.*,
|
|
||||||
m.name as poster_name
|
|
||||||
FROM discussion_posts AS p
|
|
||||||
LEFT JOIN members m ON p.poster_id = m.id
|
|
||||||
WHERE p.id = ?
|
|
||||||
LIMIT 1;
|
|
||||||
`;
|
|
||||||
const postResults = (await pool.query(postSql, [id])) as DiscussionPost<T>[];
|
|
||||||
if (postResults.length === 0) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
const post = postResults[0];
|
|
||||||
|
|
||||||
// Get comments for the post
|
|
||||||
const commentSql = `
|
|
||||||
SELECT
|
|
||||||
c.*
|
|
||||||
FROM discussion_comments AS c
|
|
||||||
WHERE c.post_id = ?
|
|
||||||
AND c.is_deleted = FALSE
|
|
||||||
ORDER BY c.created_at ASC;
|
|
||||||
`;
|
|
||||||
const comments = (await pool.query(commentSql, [id])) as DiscussionComment[];
|
|
||||||
|
|
||||||
// Attach comments to post
|
|
||||||
post.comments = comments;
|
|
||||||
|
|
||||||
return post;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getPostComments(postID: number): Promise<DiscussionComment[]> {
|
|
||||||
let comments = await pool.query("SELECT * FROM discussion_comments WHERE post_id = ?", [postID]);
|
|
||||||
return comments;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function postComment(commentData: DiscussionComment, poster: number) {
|
|
||||||
const sql = `
|
|
||||||
INSERT INTO discussion_comments (post_id, poster_id, content) VALUES (?, ?, ?);
|
|
||||||
`;
|
|
||||||
|
|
||||||
const result = await pool.query(sql, [commentData.post_id, poster, commentData.content]);
|
|
||||||
|
|
||||||
if (!result.affectedRows || result.affectedRows !== 1) {
|
|
||||||
throw new Error('Failed to insert comment: expected 1 row to be inserted');
|
|
||||||
}
|
|
||||||
|
|
||||||
return Number(result.insertId);
|
|
||||||
}
|
|
||||||
@@ -23,7 +23,8 @@ export async function getFilteredMembers(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (search) {
|
if (search) {
|
||||||
whereClauses.push(`v.member_name LIKE ?`);
|
whereClauses.push(`(v.member_name LIKE ? OR v.displayName LIKE ?)`);
|
||||||
|
params.push(`%${search}%`);
|
||||||
params.push(`%${search}%`);
|
params.push(`%${search}%`);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,7 +220,10 @@ export async function getMembersFull(ids: number[]): Promise<MemberCardDetails[]
|
|||||||
loa_until: row.loa_until ? new Date(row.loa_until) : undefined,
|
loa_until: row.loa_until ? new Date(row.loa_until) : undefined,
|
||||||
};
|
};
|
||||||
// roles comes as array of strings; parse each one
|
// roles comes as array of strings; parse each one
|
||||||
const roles: Role[] = row.roles;
|
const roles: Role[] =
|
||||||
|
typeof row.roles === "string"
|
||||||
|
? JSON.parse(row.roles)
|
||||||
|
: row.roles;
|
||||||
|
|
||||||
return { member, roles };
|
return { member, roles };
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -36,6 +36,16 @@ export async function insertMemberRank(member_id: number, rank_id: number, date?
|
|||||||
await pool.query(sql, params);
|
await pool.query(sql, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function forceInsertMemberRank(member_id: number, rank_id: number, authorized: number, creator: number, reason: string) {
|
||||||
|
const sql = `CALL sp_update_member_rank(?, ?, ?, ?, ?, NOW())`;
|
||||||
|
|
||||||
|
const result = await pool.query(sql, [member_id, rank_id, authorized, creator, reason]);
|
||||||
|
|
||||||
|
if (!result || result.affectedRows === 0) {
|
||||||
|
throw new Error("Failed to update member rank");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
export async function batchInsertMemberRank(promos: BatchPromotionMember[], author: number, approver: number) {
|
export async function batchInsertMemberRank(promos: BatchPromotionMember[], author: number, approver: number) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import pool from '../../db';
|
|||||||
import { Role, RoleSummary } from '@app/shared/types/roles'
|
import { Role, RoleSummary } from '@app/shared/types/roles'
|
||||||
import { logger } from '../logging/logger';
|
import { logger } from '../logging/logger';
|
||||||
import { memberCache } from '../../routes/auth';
|
import { memberCache } from '../../routes/auth';
|
||||||
|
import * as mariadb from 'mariadb';
|
||||||
|
|
||||||
export async function assignUserGroup(userID: number, roleID: number) {
|
export async function assignUserGroup(userID: number, roleID: number) {
|
||||||
try {
|
try {
|
||||||
@@ -62,4 +63,16 @@ export async function getUsersWithRole(roleId: number): Promise<MemberLight[]> {
|
|||||||
)
|
)
|
||||||
|
|
||||||
return out as MemberLight[]
|
return out as MemberLight[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function stripUserRoles(userID: number, con: mariadb.Pool | mariadb.Connection = pool) {
|
||||||
|
try {
|
||||||
|
const out = await con.query(`DELETE FROM members_roles WHERE member_id = ?;`, [userID]);
|
||||||
|
return { success: true, affectedRows: out.affectedRows };
|
||||||
|
} catch (error) {
|
||||||
|
logger.error('app', 'Failed to strip user roles', error);
|
||||||
|
throw error;
|
||||||
|
} finally {
|
||||||
|
memberCache.Invalidate(userID);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -10,4 +10,13 @@ export async function cancelLatestUnit(userID: number, con: mariadb.Pool | maria
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function assignNewUnit(memberID: number, unitID: number, authorizedID: number, creatorID: number, reason: string) {
|
||||||
|
let sql = `CALL sp_update_member_unit(?, ?, ?, ?, ?, NOW())`;
|
||||||
|
|
||||||
|
const result = await pool.query(sql, [memberID, unitID, authorizedID, creatorID, reason]);
|
||||||
|
if (!result || result.affectedRows === 0) {
|
||||||
|
throw new Error('Record was not updated');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import pool from "../../db";
|
import pool from "../../db";
|
||||||
import { logger } from "./logger";
|
import { logger } from "./logger";
|
||||||
|
|
||||||
export type AuditArea = 'member' | 'calendar' | 'roles' | 'auth' | 'leave_of_absence' | 'application' | 'course' | 'discussion';
|
export type AuditArea = 'member' | 'calendar' | 'roles' | 'auth' | 'leave_of_absence' | 'application' | 'course';
|
||||||
|
|
||||||
export interface AuditContext {
|
export interface AuditContext {
|
||||||
actorId: number; // The person doing the action (created_by)
|
actorId: number; // The person doing the action (created_by)
|
||||||
@@ -32,8 +32,8 @@ class AuditLogger {
|
|||||||
logger.error('audit', `AUDIT_FAILURE: Failed to log ${actionType}`, { error: err });
|
logger.error('audit', `AUDIT_FAILURE: Failed to log ${actionType}`, { error: err });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
member(action: 'update_rank' | 'suspension_added' | 'suspension_removed' | 'discharged', context: AuditContext, data: any = {}) {
|
member(action: 'update_rank'| 'update_unit' | 'suspension_added' | 'suspension_removed' | 'discharged', context: AuditContext, data: any = {}) {
|
||||||
return this.record('member', action, context, data);
|
return this.record('member', action, context, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,10 +56,6 @@ class AuditLogger {
|
|||||||
course(action: 'report_created' | 'report_edited', context: AuditContext, data: any = {}) {
|
course(action: 'report_created' | 'report_edited', context: AuditContext, data: any = {}) {
|
||||||
return this.record('course', action, context, data);
|
return this.record('course', action, context, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
discussion(action: 'created' | 'comment_posted', context: AuditContext, data: any = {}) {
|
|
||||||
return this.record('discussion', action, context, data);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const audit = new AuditLogger();
|
export const audit = new AuditLogger();
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
import { z } from 'zod';
|
|
||||||
|
|
||||||
export const ModRequestSchema = z.object({
|
|
||||||
// Basic Info
|
|
||||||
mod_title: z.string().min(1),
|
|
||||||
description: z.string().min(1),
|
|
||||||
mod_link: z.string().min(1),
|
|
||||||
|
|
||||||
// Consolidated Testing
|
|
||||||
confirmed_tested: z.boolean().refine(val => val === true, {
|
|
||||||
message: "You must confirm that you have tested this mod before submitting"
|
|
||||||
}),
|
|
||||||
|
|
||||||
// Vetting
|
|
||||||
reason: z.string().min(1),
|
|
||||||
|
|
||||||
// Compatibility & Technical
|
|
||||||
detrimental_effects: z.string().min(1),
|
|
||||||
keybind_conflicts: z.string(),
|
|
||||||
|
|
||||||
special_considerations: z.string().optional()
|
|
||||||
});
|
|
||||||
|
|
||||||
export type ModRequest = z.infer<typeof ModRequestSchema>;
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
export interface DiscussionPost<T = any> {
|
|
||||||
id: number;
|
|
||||||
type: string;
|
|
||||||
poster_id: number;
|
|
||||||
poster_name?: string;
|
|
||||||
title: string;
|
|
||||||
content: T;
|
|
||||||
created_at: Date;
|
|
||||||
updated_at: Date;
|
|
||||||
is_deleted: boolean;
|
|
||||||
is_locked: boolean;
|
|
||||||
is_open: boolean;
|
|
||||||
comments?: DiscussionComment[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface DiscussionComment {
|
|
||||||
id?: number;
|
|
||||||
post_id: number;
|
|
||||||
poster_id?: number;
|
|
||||||
content: string;
|
|
||||||
created_at?: Date;
|
|
||||||
updated_at?: Date;
|
|
||||||
is_deleted?: boolean;
|
|
||||||
}
|
|
||||||
@@ -50,4 +50,10 @@ export interface myData {
|
|||||||
LOAs: LOARequest[];
|
LOAs: LOARequest[];
|
||||||
roles: Role[];
|
roles: Role[];
|
||||||
state: MemberState;
|
state: MemberState;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface UserCacheBustResult {
|
||||||
|
success: boolean;
|
||||||
|
clearedEntries: number;
|
||||||
|
bustedAt: string;
|
||||||
}
|
}
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
import { DiscussionComment } from "@shared/types/discussion";
|
|
||||||
|
|
||||||
//@ts-expect-error
|
|
||||||
const addr = import.meta.env.VITE_APIHOST;
|
|
||||||
|
|
||||||
export async function postComment(comment: DiscussionComment) {
|
|
||||||
const res = await fetch(`${addr}/discussions/comment`, {
|
|
||||||
method: "POST",
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
},
|
|
||||||
body: JSON.stringify(comment),
|
|
||||||
credentials: 'include',
|
|
||||||
});
|
|
||||||
|
|
||||||
if (res.ok) {
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
throw new Error("Failed to submit LOA");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getPostComments(postId: number): Promise<DiscussionComment[]> {
|
|
||||||
const res = await fetch(`${addr}/discussions/${postId}/comments`, {
|
|
||||||
method: "GET",
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
},
|
|
||||||
credentials: 'include',
|
|
||||||
});
|
|
||||||
if (!res.ok) {
|
|
||||||
throw new Error("Failed to fetch comments");
|
|
||||||
}
|
|
||||||
return res.json();
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Discharge } from "@shared/schemas/dischargeSchema";
|
import { Discharge } from "@shared/schemas/dischargeSchema";
|
||||||
import { memberSettings, Member, MemberLight, MemberCardDetails, PaginatedMembers, MemberState } from "@shared/types/member";
|
import { memberSettings, Member, MemberLight, MemberCardDetails, PaginatedMembers, MemberState, UserCacheBustResult } from "@shared/types/member";
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const addr = import.meta.env.VITE_APIHOST;
|
const addr = import.meta.env.VITE_APIHOST;
|
||||||
@@ -157,4 +157,17 @@ export async function unsuspendMember(memberID: number): Promise<boolean> {
|
|||||||
throw new Error("Failed to discharge member");
|
throw new Error("Failed to discharge member");
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function bustUserCache(): Promise<UserCacheBustResult> {
|
||||||
|
const response = await fetch(`${addr}/members/cache/user/bust`, {
|
||||||
|
credentials: 'include',
|
||||||
|
method: 'POST',
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error('Failed to bust user cache');
|
||||||
|
}
|
||||||
|
|
||||||
|
return response.json();
|
||||||
}
|
}
|
||||||
@@ -1,72 +0,0 @@
|
|||||||
import { ModRequest } from "@shared/schemas/modRequest";
|
|
||||||
import { DiscussionPost } from "@shared/types/discussion";
|
|
||||||
import { PagedData } from "@shared/types/pagination";
|
|
||||||
|
|
||||||
//@ts-expect-error
|
|
||||||
const addr = import.meta.env.VITE_APIHOST;
|
|
||||||
|
|
||||||
export async function getModRequests(page?: number, pageSize?: number): Promise<PagedData<DiscussionPost<ModRequest>>> {
|
|
||||||
const params = new URLSearchParams();
|
|
||||||
|
|
||||||
if (page !== undefined) {
|
|
||||||
params.set("page", page.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pageSize !== undefined) {
|
|
||||||
params.set("pageSize", pageSize.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
return fetch(`${addr}/mod-request?${params}`, {
|
|
||||||
method: "GET",
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
},
|
|
||||||
credentials: 'include',
|
|
||||||
}).then((res) => {
|
|
||||||
if (res.ok) {
|
|
||||||
return res.json();
|
|
||||||
} else {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Posts a new mod request to the server
|
|
||||||
* @param data Form data
|
|
||||||
* @returns Numerical ID of the new post
|
|
||||||
*/
|
|
||||||
export async function postModRequest(data: ModRequest): Promise<Number> {
|
|
||||||
return fetch(`${addr}/mod-request`, {
|
|
||||||
method: "POST",
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
},
|
|
||||||
credentials: 'include',
|
|
||||||
body: JSON.stringify(data)
|
|
||||||
}).then((res) => {
|
|
||||||
if (res.ok) {
|
|
||||||
return res.text().then((id) => Number(id));
|
|
||||||
} else {
|
|
||||||
throw new Error("Failed to post mod request");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieve a single mod request by its discussion post ID
|
|
||||||
* @param id numeric post id
|
|
||||||
*/
|
|
||||||
export async function getModRequest(id: number): Promise<DiscussionPost<ModRequest>> {
|
|
||||||
const res = await fetch(`${addr}/mod-request/${id}`, {
|
|
||||||
method: 'GET',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
credentials: 'include',
|
|
||||||
});
|
|
||||||
if (!res.ok) {
|
|
||||||
throw new Error(`Failed to fetch mod request ${id}`);
|
|
||||||
}
|
|
||||||
return res.json();
|
|
||||||
}
|
|
||||||
@@ -12,4 +12,15 @@ export async function getUnits(): Promise<Unit[]> {
|
|||||||
throw new Error("Failed to fetch units");
|
throw new Error("Failed to fetch units");
|
||||||
}
|
}
|
||||||
return response.json();
|
return response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function adminAssignUnit(member: number, unit: number, rank: number, reason: string) {
|
||||||
|
const response = await fetch(`${addr}/memberUnits/admin?memberId=${member}&unitId=${unit}&rankId=${rank}&reason=${encodeURIComponent(reason)}`, {
|
||||||
|
method: 'POST',
|
||||||
|
credentials: 'include'
|
||||||
|
});
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error("Failed to assign unit");
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
@@ -1,46 +1,46 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { RouterLink } from 'vue-router';
|
import { RouterLink } from 'vue-router';
|
||||||
import Separator from '../ui/separator/Separator.vue';
|
import Separator from '../ui/separator/Separator.vue';
|
||||||
import { Popover, PopoverContent, PopoverTrigger } from '../ui/popover';
|
import { Popover, PopoverContent, PopoverTrigger } from '../ui/popover';
|
||||||
import {
|
import {
|
||||||
DropdownMenu,
|
DropdownMenu,
|
||||||
DropdownMenuContent,
|
DropdownMenuContent,
|
||||||
DropdownMenuItem,
|
DropdownMenuItem,
|
||||||
DropdownMenuTrigger,
|
DropdownMenuTrigger,
|
||||||
} from '../ui/dropdown-menu';
|
} from '../ui/dropdown-menu';
|
||||||
import { useUserStore } from '@/stores/user';
|
import { useUserStore } from '@/stores/user';
|
||||||
import Button from '../ui/button/Button.vue';
|
import Button from '../ui/button/Button.vue';
|
||||||
import NavigationMenu from '../ui/navigation-menu/NavigationMenu.vue';
|
import NavigationMenu from '../ui/navigation-menu/NavigationMenu.vue';
|
||||||
import NavigationMenuList from '../ui/navigation-menu/NavigationMenuList.vue';
|
import NavigationMenuList from '../ui/navigation-menu/NavigationMenuList.vue';
|
||||||
import NavigationMenuItem from '../ui/navigation-menu/NavigationMenuItem.vue';
|
import NavigationMenuItem from '../ui/navigation-menu/NavigationMenuItem.vue';
|
||||||
import NavigationMenuLink from '../ui/navigation-menu/NavigationMenuLink.vue';
|
import NavigationMenuLink from '../ui/navigation-menu/NavigationMenuLink.vue';
|
||||||
import NavigationMenuTrigger from '../ui/navigation-menu/NavigationMenuTrigger.vue';
|
import NavigationMenuTrigger from '../ui/navigation-menu/NavigationMenuTrigger.vue';
|
||||||
import NavigationMenuContent from '../ui/navigation-menu/NavigationMenuContent.vue';
|
import NavigationMenuContent from '../ui/navigation-menu/NavigationMenuContent.vue';
|
||||||
import { navigationMenuTriggerStyle } from '../ui/navigation-menu/'
|
import { navigationMenuTriggerStyle } from '../ui/navigation-menu/'
|
||||||
import { useAuth } from '@/composables/useAuth';
|
import { useAuth } from '@/composables/useAuth';
|
||||||
import { ArrowUpRight, CircleArrowOutUpRight } from 'lucide-vue-next';
|
import { ArrowUpRight, CircleArrowOutUpRight } from 'lucide-vue-next';
|
||||||
import DropdownMenuGroup from '../ui/dropdown-menu/DropdownMenuGroup.vue';
|
import DropdownMenuGroup from '../ui/dropdown-menu/DropdownMenuGroup.vue';
|
||||||
import DropdownMenuSeparator from '../ui/dropdown-menu/DropdownMenuSeparator.vue';
|
import DropdownMenuSeparator from '../ui/dropdown-menu/DropdownMenuSeparator.vue';
|
||||||
import { MemberState } from '@shared/types/member';
|
import { MemberState } from '@shared/types/member';
|
||||||
|
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
const auth = useAuth();
|
const auth = useAuth();
|
||||||
|
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
const APIHOST = import.meta.env.VITE_APIHOST;
|
const APIHOST = import.meta.env.VITE_APIHOST;
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
const DOCHOST = import.meta.env.VITE_DOCHOST;
|
const DOCHOST = import.meta.env.VITE_DOCHOST;
|
||||||
|
|
||||||
async function logout() {
|
async function logout() {
|
||||||
userStore.user = null;
|
userStore.user = null;
|
||||||
window.location.href = APIHOST + "/logout";
|
window.location.href = APIHOST + "/logout";
|
||||||
}
|
}
|
||||||
|
|
||||||
function blurAfter() {
|
function blurAfter() {
|
||||||
requestAnimationFrame(() => {
|
requestAnimationFrame(() => {
|
||||||
(document.activeElement as HTMLElement)?.blur();
|
(document.activeElement as HTMLElement)?.blur();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -52,8 +52,7 @@
|
|||||||
<img src="/17RBN_Logo.png" class="w-10 h-10 object-contain"></img>
|
<img src="/17RBN_Logo.png" class="w-10 h-10 object-contain"></img>
|
||||||
</RouterLink>
|
</RouterLink>
|
||||||
<!-- Member navigation -->
|
<!-- Member navigation -->
|
||||||
<div v-if="auth.accountStatus.value == MemberState.Member"
|
<div v-if="auth.accountStatus.value == MemberState.Member" class="h-15 flex items-center justify-center">
|
||||||
class="h-15 flex items-center justify-center">
|
|
||||||
<NavigationMenu>
|
<NavigationMenu>
|
||||||
<NavigationMenuList class="gap-3">
|
<NavigationMenuList class="gap-3">
|
||||||
|
|
||||||
@@ -102,19 +101,6 @@
|
|||||||
</NavigationMenuContent>
|
</NavigationMenuContent>
|
||||||
</NavigationMenuItem>
|
</NavigationMenuItem>
|
||||||
|
|
||||||
<!-- Discussions (Dropdown) -->
|
|
||||||
<NavigationMenuItem class="bg-none !focus:bg-none !active:bg-none">
|
|
||||||
<NavigationMenuTrigger>Discussions</NavigationMenuTrigger>
|
|
||||||
<NavigationMenuContent
|
|
||||||
class="grid gap-1 p-2 text-left [&_a]:w-full [&_a]:block [&_a]:whitespace-nowrap *:bg-transparent">
|
|
||||||
<NavigationMenuLink as-child :class="navigationMenuTriggerStyle()">
|
|
||||||
<RouterLink to="/discussions/mod-requests" @click="blurAfter">
|
|
||||||
Mod Requests
|
|
||||||
</RouterLink>
|
|
||||||
</NavigationMenuLink>
|
|
||||||
</NavigationMenuContent>
|
|
||||||
</NavigationMenuItem>
|
|
||||||
|
|
||||||
<!-- Administration (Dropdown) -->
|
<!-- Administration (Dropdown) -->
|
||||||
<NavigationMenuItem
|
<NavigationMenuItem
|
||||||
v-if="auth.hasAnyRole(['17th Administrator', '17th HQ', '17th Command', 'Recruiter'])">
|
v-if="auth.hasAnyRole(['17th Administrator', '17th HQ', '17th Command', 'Recruiter'])">
|
||||||
@@ -167,6 +153,12 @@
|
|||||||
</NavigationMenuLink>
|
</NavigationMenuLink>
|
||||||
</NavigationMenuContent>
|
</NavigationMenuContent>
|
||||||
</NavigationMenuItem>
|
</NavigationMenuItem>
|
||||||
|
|
||||||
|
<NavigationMenuItem v-if="auth.hasRole('Dev')">
|
||||||
|
<NavigationMenuLink as-child :class="navigationMenuTriggerStyle()">
|
||||||
|
<RouterLink to="/developer" @click="blurAfter">Developer</RouterLink>
|
||||||
|
</NavigationMenuLink>
|
||||||
|
</NavigationMenuItem>
|
||||||
</NavigationMenuList>
|
</NavigationMenuList>
|
||||||
</NavigationMenu>
|
</NavigationMenu>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,42 +0,0 @@
|
|||||||
<script setup lang="ts">
|
|
||||||
import { ref } from 'vue';
|
|
||||||
import Textarea from '../ui/textarea/Textarea.vue';
|
|
||||||
import Button from '../ui/button/Button.vue';
|
|
||||||
import { postComment } from '@/api/discussion';
|
|
||||||
import { DiscussionComment } from '@shared/types/discussion';
|
|
||||||
|
|
||||||
const props = defineProps<{
|
|
||||||
parentId: number,
|
|
||||||
}>();
|
|
||||||
|
|
||||||
const emit = defineEmits(['commentPosted']);
|
|
||||||
const commentText = ref('');
|
|
||||||
const error = ref('');
|
|
||||||
|
|
||||||
async function submitComment(e: Event) {
|
|
||||||
e.preventDefault();
|
|
||||||
error.value = '';
|
|
||||||
if (!commentText.value.trim()) {
|
|
||||||
error.value = 'Comment cannot be empty';
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let newComment: DiscussionComment = { post_id: props.parentId, content: commentText.value.trim() };
|
|
||||||
await postComment(newComment);
|
|
||||||
emit('commentPosted');
|
|
||||||
commentText.value = '';
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<form @submit="submitComment">
|
|
||||||
<div class="mb-2">
|
|
||||||
<label class="block font-medium mb-1">Add a comment</label>
|
|
||||||
<Textarea rows="3" class="bg-neutral-800 resize-none w-full" v-model="commentText"
|
|
||||||
placeholder="Add a comment…" />
|
|
||||||
<div class="h-4 text-red-500 text-sm mt-1" v-if="error">{{ error }}</div>
|
|
||||||
</div>
|
|
||||||
<div class="mt-2 flex justify-end">
|
|
||||||
<Button type="submit" :disabled="!commentText.trim()">Post Comment</Button>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</template>
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
<script setup lang="ts">
|
|
||||||
|
|
||||||
import { DiscussionComment } from '@shared/types/discussion';
|
|
||||||
import DiscussionCommentView from './DiscussionCommentView.vue';
|
|
||||||
import CommentForm from './CommentForm.vue';
|
|
||||||
import { ref } from 'process';
|
|
||||||
import { getPostComments } from '@/api/discussion';
|
|
||||||
|
|
||||||
const props = defineProps<{
|
|
||||||
parentId: number,
|
|
||||||
comments: DiscussionComment[]
|
|
||||||
}>()
|
|
||||||
|
|
||||||
const emit = defineEmits<{
|
|
||||||
(e: 'commentsUpdated', comments: DiscussionComment[]): void
|
|
||||||
}>()
|
|
||||||
|
|
||||||
async function onCommentPosted() {
|
|
||||||
const res = await getPostComments(props.parentId);
|
|
||||||
console.log(res);
|
|
||||||
// tell parent to update state
|
|
||||||
emit('commentsUpdated', res);
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<div class="mt-10 *:my-5">
|
|
||||||
<h3 class="text-xl font-semibold">Discussion</h3>
|
|
||||||
<div class="comment-thread">
|
|
||||||
<div class="comments-list flex flex-col gap-5">
|
|
||||||
<div v-for="comment in comments" :key="comment.id" class="comment">
|
|
||||||
<DiscussionCommentView :comment="comment"></DiscussionCommentView>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<CommentForm :parent-id="props.parentId" @commentPosted="onCommentPosted" />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
<script setup lang="ts">
|
|
||||||
import { DiscussionComment } from '@shared/types/discussion';
|
|
||||||
import MemberCard from '../members/MemberCard.vue';
|
|
||||||
|
|
||||||
const props = defineProps<{
|
|
||||||
comment: DiscussionComment;
|
|
||||||
}>();
|
|
||||||
</script>
|
|
||||||
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<div class="rounded-md border border-neutral-800 p-3 space-y-5">
|
|
||||||
<!-- Comment header -->
|
|
||||||
<div class="flex justify-between">
|
|
||||||
<MemberCard :member-id="comment.poster_id"></MemberCard>
|
|
||||||
<p class="text-muted-foreground">{{ new Date(comment.created_at).toLocaleString("EN-us", {
|
|
||||||
year: "numeric",
|
|
||||||
month: "long",
|
|
||||||
day: "numeric",
|
|
||||||
hour: "2-digit",
|
|
||||||
minute: "2-digit"
|
|
||||||
}) }}</p>
|
|
||||||
</div>
|
|
||||||
<p>{{ comment.content }}</p>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
@@ -26,7 +26,10 @@ const props = defineProps<{
|
|||||||
member: Member | null
|
member: Member | null
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const emit = defineEmits(['update:open', 'discharged'])
|
const emit = defineEmits<{
|
||||||
|
'update:open': [value: boolean]
|
||||||
|
'discharged': [value: { data: Discharge }]
|
||||||
|
}>()
|
||||||
|
|
||||||
const formSchema = toTypedSchema(dischargeSchema);
|
const formSchema = toTypedSchema(dischargeSchema);
|
||||||
|
|
||||||
|
|||||||
250
ui/src/components/members/TransferMember.vue
Normal file
250
ui/src/components/members/TransferMember.vue
Normal file
@@ -0,0 +1,250 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { computed, ref, watch } from 'vue'
|
||||||
|
|
||||||
|
import { adminAssignUnit, getUnits } from '@/api/units'
|
||||||
|
import { getAllRanks } from '@/api/rank'
|
||||||
|
import { Button } from '@/components/ui/button'
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogDescription,
|
||||||
|
DialogFooter,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
} from '@/components/ui/dialog'
|
||||||
|
import { Field, FieldError, FieldLabel } from '@/components/ui/field'
|
||||||
|
import { Input } from '@/components/ui/input'
|
||||||
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
} from '@/components/ui/select'
|
||||||
|
import MemberCard from './MemberCard.vue'
|
||||||
|
import type { Member } from '@shared/types/member'
|
||||||
|
import type { Rank } from '@shared/types/rank'
|
||||||
|
import type { Unit } from '@shared/types/units'
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
open: boolean
|
||||||
|
member: Member | null
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
'update:open': [value: boolean]
|
||||||
|
transferred: [value: { memberId: number; unitId: number; rankId: number; reason: string }]
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const units = ref<Unit[]>([])
|
||||||
|
const ranks = ref<Rank[]>([])
|
||||||
|
const loadingUnits = ref(false)
|
||||||
|
const loadingRanks = ref(false)
|
||||||
|
const submitting = ref(false)
|
||||||
|
const formError = ref('')
|
||||||
|
|
||||||
|
const selectedUnitId = ref('')
|
||||||
|
const selectedRankId = ref('')
|
||||||
|
const selectedReason = ref('transfer_request')
|
||||||
|
const customReason = ref('')
|
||||||
|
|
||||||
|
const reasonOptions = [
|
||||||
|
{ label: 'Transfer Request', value: 'transfer_request' },
|
||||||
|
{ label: 'Leadership Vote', value: 'leadership_vote' },
|
||||||
|
{ label: 'Appointment', value: 'appointment' },
|
||||||
|
{ label: 'Step Down', value: 'step_down' },
|
||||||
|
{ label: 'Custom', value: 'custom' },
|
||||||
|
]
|
||||||
|
|
||||||
|
const resolvedReason = computed(() => {
|
||||||
|
if (selectedReason.value === 'custom') {
|
||||||
|
return customReason.value.trim()
|
||||||
|
}
|
||||||
|
return selectedReason.value
|
||||||
|
})
|
||||||
|
|
||||||
|
const canSubmit = computed(() => {
|
||||||
|
return !!props.member && !!selectedUnitId.value && !!selectedRankId.value && !!resolvedReason.value
|
||||||
|
})
|
||||||
|
|
||||||
|
function resolveDefaultRankId(member: Member | null): string {
|
||||||
|
if (!member || !member.rank) {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
|
||||||
|
const normalizedMemberRank = member.rank.trim().toLowerCase()
|
||||||
|
const matchedRank = ranks.value.find((rank) => {
|
||||||
|
return rank.name.trim().toLowerCase() === normalizedMemberRank
|
||||||
|
|| rank.short_name.trim().toLowerCase() === normalizedMemberRank
|
||||||
|
})
|
||||||
|
|
||||||
|
return matchedRank ? String(matchedRank.id) : ''
|
||||||
|
}
|
||||||
|
|
||||||
|
function resetForm() {
|
||||||
|
selectedUnitId.value = ''
|
||||||
|
selectedRankId.value = ''
|
||||||
|
selectedReason.value = 'transfer_request'
|
||||||
|
customReason.value = ''
|
||||||
|
formError.value = ''
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadUnits() {
|
||||||
|
loadingUnits.value = true
|
||||||
|
formError.value = ''
|
||||||
|
try {
|
||||||
|
units.value = await getUnits()
|
||||||
|
} catch {
|
||||||
|
formError.value = 'Failed to load units. Please try again.'
|
||||||
|
} finally {
|
||||||
|
loadingUnits.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadRanks() {
|
||||||
|
loadingRanks.value = true
|
||||||
|
formError.value = ''
|
||||||
|
try {
|
||||||
|
ranks.value = await getAllRanks()
|
||||||
|
selectedRankId.value = resolveDefaultRankId(props.member)
|
||||||
|
} catch {
|
||||||
|
formError.value = 'Failed to load ranks. Please try again.'
|
||||||
|
} finally {
|
||||||
|
loadingRanks.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => props.open,
|
||||||
|
(isOpen) => {
|
||||||
|
if (isOpen) {
|
||||||
|
resetForm()
|
||||||
|
loadUnits()
|
||||||
|
loadRanks()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
async function onSubmit() {
|
||||||
|
if (!props.member) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!selectedUnitId.value) {
|
||||||
|
formError.value = 'Please select a target unit.'
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!selectedRankId.value) {
|
||||||
|
formError.value = 'Please select a target rank.'
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!resolvedReason.value) {
|
||||||
|
formError.value = 'Please select a reason or enter a custom reason.'
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
submitting.value = true
|
||||||
|
formError.value = ''
|
||||||
|
try {
|
||||||
|
const unitId = Number(selectedUnitId.value)
|
||||||
|
const rankId = Number(selectedRankId.value)
|
||||||
|
await adminAssignUnit(props.member.member_id, unitId, rankId, resolvedReason.value)
|
||||||
|
|
||||||
|
emit('transferred', {
|
||||||
|
memberId: props.member.member_id,
|
||||||
|
unitId,
|
||||||
|
rankId,
|
||||||
|
reason: resolvedReason.value,
|
||||||
|
})
|
||||||
|
emit('update:open', false)
|
||||||
|
} catch {
|
||||||
|
formError.value = 'Failed to transfer member. Please try again.'
|
||||||
|
} finally {
|
||||||
|
submitting.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Dialog :open="open" @update:open="emit('update:open', $event)">
|
||||||
|
<DialogContent class="sm:max-w-[425px]">
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>Transfer Member</DialogTitle>
|
||||||
|
<DialogDescription>
|
||||||
|
Select a new unit assignment for
|
||||||
|
<MemberCard v-if="member" :member-id="member.member_id" />
|
||||||
|
</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
|
||||||
|
<form id="transferForm" @submit.prevent="onSubmit" class="space-y-4 py-2">
|
||||||
|
<Field>
|
||||||
|
<FieldLabel>Target Unit</FieldLabel>
|
||||||
|
<Select v-model="selectedUnitId" :disabled="loadingUnits || submitting">
|
||||||
|
<SelectTrigger>
|
||||||
|
<SelectValue placeholder="Select unit" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem v-for="unit in units" :key="unit.id" :value="String(unit.id)">
|
||||||
|
{{ unit.name }}
|
||||||
|
</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</Field>
|
||||||
|
|
||||||
|
<Field>
|
||||||
|
<FieldLabel>Target Rank</FieldLabel>
|
||||||
|
<Select v-model="selectedRankId" :disabled="loadingRanks || submitting">
|
||||||
|
<SelectTrigger>
|
||||||
|
<SelectValue placeholder="Select rank" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem v-for="rank in ranks" :key="rank.id" :value="String(rank.id)">
|
||||||
|
{{ rank.name }}
|
||||||
|
</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</Field>
|
||||||
|
|
||||||
|
<Field>
|
||||||
|
<FieldLabel>Reason</FieldLabel>
|
||||||
|
<Select v-model="selectedReason" :disabled="submitting">
|
||||||
|
<SelectTrigger>
|
||||||
|
<SelectValue placeholder="Select reason" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem
|
||||||
|
v-for="reason in reasonOptions"
|
||||||
|
:key="reason.value"
|
||||||
|
:value="reason.value"
|
||||||
|
>
|
||||||
|
{{ reason.label }}
|
||||||
|
</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</Field>
|
||||||
|
|
||||||
|
<Field v-if="selectedReason === 'custom'">
|
||||||
|
<FieldLabel>Custom Reason</FieldLabel>
|
||||||
|
<Input
|
||||||
|
v-model="customReason"
|
||||||
|
:disabled="submitting"
|
||||||
|
placeholder="Enter custom transfer reason"
|
||||||
|
/>
|
||||||
|
</Field>
|
||||||
|
|
||||||
|
<FieldError v-if="formError" :errors="[formError]" />
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<DialogFooter class="gap-2">
|
||||||
|
<Button variant="ghost" @click="emit('update:open', false)">
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
<Button type="submit" form="transferForm" :disabled="!canSubmit || loadingUnits || loadingRanks || submitting">
|
||||||
|
{{ submitting ? 'Transferring...' : 'Transfer Member' }}
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
</template>
|
||||||
@@ -1,241 +0,0 @@
|
|||||||
<script setup lang="ts">
|
|
||||||
import { ModRequestSchema } from '@shared/schemas/modRequest'
|
|
||||||
import { useForm, Field as VeeField } from 'vee-validate'
|
|
||||||
import { toTypedSchema } from '@vee-validate/zod'
|
|
||||||
import { ref } from 'vue'
|
|
||||||
import Button from '@/components/ui/button/Button.vue'
|
|
||||||
import Field from '@/components/ui/field/Field.vue'
|
|
||||||
import FieldLabel from '@/components/ui/field/FieldLabel.vue'
|
|
||||||
import FieldError from '@/components/ui/field/FieldError.vue'
|
|
||||||
import FieldDescription from '@/components/ui/field/FieldDescription.vue'
|
|
||||||
import Input from '@/components/ui/input/Input.vue'
|
|
||||||
import Textarea from '@/components/ui/textarea/Textarea.vue'
|
|
||||||
import Checkbox from '@/components/ui/checkbox/Checkbox.vue'
|
|
||||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
|
|
||||||
import { Separator } from '@/components/ui/separator'
|
|
||||||
import { X } from 'lucide-vue-next'
|
|
||||||
import { postModRequest } from '@/api/modRequests'
|
|
||||||
|
|
||||||
const { handleSubmit, resetForm, errors } = useForm({
|
|
||||||
validationSchema: toTypedSchema(ModRequestSchema),
|
|
||||||
validateOnMount: false,
|
|
||||||
initialValues: {
|
|
||||||
mod_title: '',
|
|
||||||
description: '',
|
|
||||||
mod_link: '',
|
|
||||||
confirmed_tested: false,
|
|
||||||
reason: '',
|
|
||||||
detrimental_effects: '',
|
|
||||||
keybind_conflicts: '',
|
|
||||||
special_considerations: '',
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
const submitting = ref(false)
|
|
||||||
const emit = defineEmits(['submit', 'close'])
|
|
||||||
|
|
||||||
const submitForm = handleSubmit(async (values) => {
|
|
||||||
if (submitting.value) return
|
|
||||||
submitting.value = true
|
|
||||||
try {
|
|
||||||
await postModRequest(values);
|
|
||||||
emit('submit', values)
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Error submitting mod request:', err)
|
|
||||||
} finally {
|
|
||||||
submitting.value = false
|
|
||||||
}
|
|
||||||
})
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<Card class="border-0 shadow-sm">
|
|
||||||
<CardHeader>
|
|
||||||
<div class="flex items-start justify-between">
|
|
||||||
<div class="flex-1">
|
|
||||||
<CardTitle>New Mod Request</CardTitle>
|
|
||||||
<CardDescription>Share details about the mod you'd like to see added to our server</CardDescription>
|
|
||||||
</div>
|
|
||||||
<Button type="button" variant="ghost" @click="emit('close')"
|
|
||||||
class="text-muted-foreground hover:text-foreground -mt-1 -mr-2">
|
|
||||||
Back to posts <X></X>
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</CardHeader>
|
|
||||||
|
|
||||||
<Separator class="mb-0" />
|
|
||||||
|
|
||||||
<CardContent>
|
|
||||||
<form @submit.prevent="submitForm" class="space-y-8">
|
|
||||||
<!-- SECTION: Basic Mod Information -->
|
|
||||||
<div class="space-y-5">
|
|
||||||
<div class="space-y-1">
|
|
||||||
<h3 class="font-semibold text-sm text-foreground">Mod Information</h3>
|
|
||||||
<p class="text-xs text-muted-foreground">Core details about the mod</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="space-y-5">
|
|
||||||
<!-- Title -->
|
|
||||||
<VeeField name="mod_title" v-slot="{ field, errors: e }">
|
|
||||||
<Field :data-invalid="!!e.length">
|
|
||||||
<FieldLabel class="text-sm font-medium">Mod Title</FieldLabel>
|
|
||||||
<Input v-bind="field" placeholder="Name of the mod" rows="4" class="resize-none mt-2" />
|
|
||||||
<div class="h-4">
|
|
||||||
<FieldError v-if="e.length" :errors="e" />
|
|
||||||
</div>
|
|
||||||
</Field>
|
|
||||||
</VeeField>
|
|
||||||
|
|
||||||
<!-- Description -->
|
|
||||||
<VeeField name="description" v-slot="{ field, errors: e }">
|
|
||||||
<Field :data-invalid="!!e.length">
|
|
||||||
<FieldLabel class="text-sm font-medium">What is this mod?</FieldLabel>
|
|
||||||
<FieldDescription class="text-xs">Brief overview of the mod and its main functionality
|
|
||||||
</FieldDescription>
|
|
||||||
<Textarea v-bind="field" placeholder="Describe what this mod does..." rows="4"
|
|
||||||
class="resize-none mt-2" />
|
|
||||||
<div class="h-4">
|
|
||||||
<FieldError v-if="e.length" :errors="e" />
|
|
||||||
</div>
|
|
||||||
</Field>
|
|
||||||
</VeeField>
|
|
||||||
|
|
||||||
<!-- Mod Link -->
|
|
||||||
<VeeField name="mod_link" v-slot="{ field, errors: e }">
|
|
||||||
<Field :data-invalid="!!e.length">
|
|
||||||
<FieldLabel class="text-sm font-medium">Mod Link</FieldLabel>
|
|
||||||
<FieldDescription class="text-xs">Where can this mod be found?</FieldDescription>
|
|
||||||
<Input v-bind="field" placeholder="https://..." class="mt-2" />
|
|
||||||
<div class="h-4">
|
|
||||||
<FieldError v-if="e.length" :errors="e" />
|
|
||||||
</div>
|
|
||||||
</Field>
|
|
||||||
</VeeField>
|
|
||||||
|
|
||||||
<!-- Reason -->
|
|
||||||
<VeeField name="reason" v-slot="{ field, errors: e }">
|
|
||||||
<Field :data-invalid="!!e.length">
|
|
||||||
<FieldLabel class="text-sm font-medium">Why add this mod?</FieldLabel>
|
|
||||||
<FieldDescription class="text-xs">What benefits does this mod bring to our community and
|
|
||||||
why should we consider it?
|
|
||||||
</FieldDescription>
|
|
||||||
<Textarea v-bind="field" placeholder="Share your thoughts..." rows="3"
|
|
||||||
class="resize-none mt-2" />
|
|
||||||
<div class="h-4">
|
|
||||||
<FieldError v-if="e.length" :errors="e" />
|
|
||||||
</div>
|
|
||||||
</Field>
|
|
||||||
</VeeField>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<Separator />
|
|
||||||
|
|
||||||
<!-- SECTION: Testing & Verification -->
|
|
||||||
<div class="space-y-5">
|
|
||||||
<div class="space-y-1">
|
|
||||||
<h3 class="font-semibold text-sm text-foreground">Testing & Verification</h3>
|
|
||||||
<p class="text-xs text-muted-foreground">Your experience with this mod</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="space-y-5">
|
|
||||||
<!-- Confirmed Tested -->
|
|
||||||
<VeeField name="confirmed_tested" v-slot="{ field, errors: e }">
|
|
||||||
<Field :data-invalid="!!e.length">
|
|
||||||
<div class="flex items-center gap-3 p-3 rounded-md bg-muted/30 border border-border/50">
|
|
||||||
<Checkbox :model-value="field.value" @update:model-value="field.onChange"
|
|
||||||
class="hover:cursor-pointer" />
|
|
||||||
<div class="flex-1">
|
|
||||||
<FieldLabel class="font-medium text-md cursor-pointer">Testing & Stability
|
|
||||||
Confirmation
|
|
||||||
</FieldLabel>
|
|
||||||
<FieldDescription class="text-sm">I confirm that I have personally tested this
|
|
||||||
mod and to the best of my ability have verified that it functions as
|
|
||||||
described without
|
|
||||||
causing game-breaking bugs,
|
|
||||||
critical stability issues, or unintended performance degradation.
|
|
||||||
</FieldDescription>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="h-4">
|
|
||||||
<FieldError v-if="e.length" :errors="e" />
|
|
||||||
</div>
|
|
||||||
</Field>
|
|
||||||
</VeeField>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<Separator />
|
|
||||||
|
|
||||||
<!-- SECTION: Compatibility -->
|
|
||||||
<div class="space-y-5">
|
|
||||||
<div class="space-y-1">
|
|
||||||
<h3 class="font-semibold text-sm text-foreground">Compatibility & Conflicts</h3>
|
|
||||||
<p class="text-xs text-muted-foreground">How does it work with our current setup?</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="space-y-5">
|
|
||||||
<!-- Detrimental Effects -->
|
|
||||||
<VeeField name="detrimental_effects" v-slot="{ field, errors: e }">
|
|
||||||
<Field :data-invalid="!!e.length">
|
|
||||||
<FieldLabel class="text-sm font-medium">Potential Issues</FieldLabel>
|
|
||||||
<FieldDescription class="text-xs">Any negative impacts or concerns you noticed (Keybind
|
|
||||||
conflicts sould be noted in the dedicated section)?
|
|
||||||
</FieldDescription>
|
|
||||||
<Textarea v-bind="field" placeholder="List any issues... (leave blank if none)" rows="3"
|
|
||||||
class="resize-none mt-2" />
|
|
||||||
<div class="h-4">
|
|
||||||
<FieldError v-if="e.length" :errors="e" />
|
|
||||||
</div>
|
|
||||||
</Field>
|
|
||||||
</VeeField>
|
|
||||||
|
|
||||||
<!-- Keybind Conflicts -->
|
|
||||||
<VeeField name="keybind_conflicts" v-slot="{ field, errors: e }">
|
|
||||||
<Field :data-invalid="!!e.length">
|
|
||||||
<FieldLabel class="text-sm font-medium">Keybind Conflicts</FieldLabel>
|
|
||||||
<FieldDescription class="text-xs">Identify any controls that conflict with the existing
|
|
||||||
modpack along with resolutions for those conflicts.
|
|
||||||
</FieldDescription>
|
|
||||||
<Textarea v-bind="field"
|
|
||||||
placeholder='List specific conflicts and resolutions here, or type "None" if there are no conflicts.'
|
|
||||||
rows="3" class="resize-none mt-2" />
|
|
||||||
<div class="h-4">
|
|
||||||
<FieldError v-if="e.length" :errors="e" />
|
|
||||||
</div>
|
|
||||||
</Field>
|
|
||||||
</VeeField>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<Separator />
|
|
||||||
|
|
||||||
<!-- SECTION: Additional Notes -->
|
|
||||||
<div class="space-y-5">
|
|
||||||
<div class="space-y-5">
|
|
||||||
<!-- Special Considerations -->
|
|
||||||
<VeeField name="special_considerations" v-slot="{ field, errors: e }">
|
|
||||||
<Field :data-invalid="!!e.length">
|
|
||||||
<FieldLabel class="text-sm font-medium">Additional Information</FieldLabel>
|
|
||||||
<FieldDescription class="text-xs">Anything else we should know?</FieldDescription>
|
|
||||||
<Textarea v-bind="field" placeholder="Add any other important notes... (optional)"
|
|
||||||
rows="4" class="resize-none mt-2" />
|
|
||||||
<div class="h-4">
|
|
||||||
<FieldError v-if="e.length" :errors="e" />
|
|
||||||
</div>
|
|
||||||
</Field>
|
|
||||||
</VeeField>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Action Buttons -->
|
|
||||||
<div class="flex gap-2 justify-end pt-4">
|
|
||||||
<Button type="button" variant="outline" @click="resetForm">Clear</Button>
|
|
||||||
<Button type="submit" :disabled="submitting">
|
|
||||||
{{ submitting ? 'Submitting...' : 'Submit Request' }}
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
</template>
|
|
||||||
@@ -1,125 +0,0 @@
|
|||||||
<script setup lang="ts">
|
|
||||||
import { ref, onMounted } from 'vue';
|
|
||||||
import type { DiscussionPost } from '@shared/types/discussion';
|
|
||||||
import type { ModRequest } from '@shared/schemas/modRequest';
|
|
||||||
import type { PagedData, pagination } from '@shared/types/pagination';
|
|
||||||
import {
|
|
||||||
Table,
|
|
||||||
TableBody,
|
|
||||||
TableCell,
|
|
||||||
TableHead,
|
|
||||||
TableHeader,
|
|
||||||
TableRow,
|
|
||||||
} from '@/components/ui/table';
|
|
||||||
import Badge from '@/components/ui/badge/Badge.vue';
|
|
||||||
import { getModRequests } from '@/api/modRequests';
|
|
||||||
import Pagination from '../ui/pagination/Pagination.vue';
|
|
||||||
import PaginationContent from '../ui/pagination/PaginationContent.vue';
|
|
||||||
import PaginationPrevious from '../ui/pagination/PaginationPrevious.vue';
|
|
||||||
import PaginationItem from '../ui/pagination/PaginationItem.vue';
|
|
||||||
import PaginationEllipsis from '../ui/pagination/PaginationEllipsis.vue';
|
|
||||||
import PaginationNext from '../ui/pagination/PaginationNext.vue';
|
|
||||||
import { Lock } from 'lucide-vue-next';
|
|
||||||
|
|
||||||
const requests = ref<DiscussionPost<ModRequest>[]>([]);
|
|
||||||
const loading = ref(true);
|
|
||||||
|
|
||||||
async function loadRequests() {
|
|
||||||
loading.value = true;
|
|
||||||
try {
|
|
||||||
const response = await getModRequests(pageNum.value, pageSize.value);
|
|
||||||
|
|
||||||
requests.value = response.data;
|
|
||||||
pageData.value = response.pagination;
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Failed to load requests:", error);
|
|
||||||
} finally {
|
|
||||||
loading.value = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onMounted(() => {
|
|
||||||
loadRequests();
|
|
||||||
});
|
|
||||||
|
|
||||||
const pageNum = ref<number>(1);
|
|
||||||
const pageData = ref<pagination>();
|
|
||||||
|
|
||||||
const pageSize = ref<number>(15)
|
|
||||||
const pageSizeOptions = [10, 15, 30]
|
|
||||||
|
|
||||||
function setPageSize(size: number) {
|
|
||||||
pageSize.value = size;
|
|
||||||
pageNum.value = 1;
|
|
||||||
loadRequests();
|
|
||||||
}
|
|
||||||
|
|
||||||
function setPage(pagenum: number) {
|
|
||||||
pageNum.value = pagenum;
|
|
||||||
loadRequests();
|
|
||||||
}
|
|
||||||
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<div class="mod-request-list">
|
|
||||||
<Table v-if="!loading">
|
|
||||||
<TableHeader>
|
|
||||||
<TableRow>
|
|
||||||
<TableHead class="w-1/2">Title</TableHead>
|
|
||||||
<TableHead class="w-1/4">Creator</TableHead>
|
|
||||||
<TableHead class="w-1/4">Date</TableHead>
|
|
||||||
<TableHead class="w-1/5 text-right">Status</TableHead>
|
|
||||||
</TableRow>
|
|
||||||
</TableHeader>
|
|
||||||
<TableBody>
|
|
||||||
<TableRow v-for="post in requests" :key="post.id"
|
|
||||||
class="hover:bg-muted/50 cursor-pointer transition-colors"
|
|
||||||
@click="$router.push(`/discussions/mod-requests/${post.id}`)">
|
|
||||||
<TableCell class="font-medium">{{ post.title }}</TableCell>
|
|
||||||
<TableCell>{{ post.poster_name }}</TableCell>
|
|
||||||
<TableCell class="text-muted-foreground">{{ new Date(post.created_at).toLocaleDateString() }}
|
|
||||||
</TableCell>
|
|
||||||
<TableCell class="text-right">
|
|
||||||
<Badge :variant="post.is_open ? 'secondary' : 'outline'">
|
|
||||||
{{ post.is_open ? 'Open' : 'Locked' }}
|
|
||||||
<Lock v-if="!post.is_open" />
|
|
||||||
</Badge>
|
|
||||||
</TableCell>
|
|
||||||
</TableRow>
|
|
||||||
</TableBody>
|
|
||||||
</Table>
|
|
||||||
<div v-else class="flex items-center justify-center py-12">
|
|
||||||
<p class="text-muted-foreground">Loading requests...</p>
|
|
||||||
</div>
|
|
||||||
<div class="mt-5 flex justify-between">
|
|
||||||
<div></div>
|
|
||||||
<Pagination v-slot="{ page }" :items-per-page="pageData?.pageSize || 10" :total="pageData?.total || 10"
|
|
||||||
:default-page="2" :page="pageNum" @update:page="setPage">
|
|
||||||
<PaginationContent v-slot="{ items }">
|
|
||||||
<PaginationPrevious />
|
|
||||||
<template v-for="(item, index) in items" :key="index">
|
|
||||||
<PaginationItem v-if="item.type === 'page'" :value="item.value"
|
|
||||||
:is-active="item.value === page">
|
|
||||||
{{ item.value }}
|
|
||||||
</PaginationItem>
|
|
||||||
</template>
|
|
||||||
<PaginationEllipsis :index="4" />
|
|
||||||
<PaginationNext />
|
|
||||||
</PaginationContent>
|
|
||||||
</Pagination>
|
|
||||||
<div class="flex items-center gap-3 text-sm">
|
|
||||||
<p class="text-muted-foreground text-nowrap">Per page:</p>
|
|
||||||
|
|
||||||
<button v-for="size in pageSizeOptions" :key="size" @click="setPageSize(size)"
|
|
||||||
class="px-2 py-1 rounded transition-colors" :class="{
|
|
||||||
'bg-muted font-semibold': pageSize === size,
|
|
||||||
'hover:bg-muted/50': pageSize !== size
|
|
||||||
}">
|
|
||||||
{{ size }}
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
@@ -1,106 +0,0 @@
|
|||||||
<script setup lang="ts">
|
|
||||||
import { ref, onMounted } from 'vue';
|
|
||||||
import { useRoute, useRouter } from 'vue-router';
|
|
||||||
import type { DiscussionPost } from '@shared/types/discussion';
|
|
||||||
import type { ModRequest } from '@shared/schemas/modRequest';
|
|
||||||
import { getModRequest } from '@/api/modRequests';
|
|
||||||
import Button from '@/components/ui/button/Button.vue';
|
|
||||||
import Badge from '@/components/ui/badge/Badge.vue';
|
|
||||||
import CommentThread from '../discussion/CommentThread.vue';
|
|
||||||
|
|
||||||
const route = useRoute();
|
|
||||||
const router = useRouter();
|
|
||||||
|
|
||||||
const post = ref<DiscussionPost<ModRequest> | null>(null);
|
|
||||||
const loading = ref(true);
|
|
||||||
const error = ref<string | null>(null);
|
|
||||||
|
|
||||||
async function loadPost() {
|
|
||||||
loading.value = true;
|
|
||||||
error.value = null;
|
|
||||||
try {
|
|
||||||
const id = Number(route.params.id);
|
|
||||||
if (isNaN(id)) {
|
|
||||||
error.value = 'Invalid request ID';
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
post.value = await getModRequest(id);
|
|
||||||
} catch (err: any) {
|
|
||||||
console.error('Failed to fetch mod request', err);
|
|
||||||
error.value = 'Failed to load mod request';
|
|
||||||
} finally {
|
|
||||||
loading.value = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onMounted(() => {
|
|
||||||
loadPost();
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<div class="max-w-[80rem] mt-5 mx-auto px-2 lg:px-20 w-full">
|
|
||||||
<div class="mb-8 flex items-center justify-between">
|
|
||||||
<div>
|
|
||||||
<h1 class="scroll-m-20 text-3xl font-semibold tracking-tight mb-2">Mod Request: {{ post?.title }}</h1>
|
|
||||||
<p class="text-muted-foreground" v-if="post">
|
|
||||||
Requested by {{ post.poster_name || 'Unknown' }} on {{ new
|
|
||||||
Date(post.created_at).toLocaleDateString() }}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<Button variant="outline" @click="router.push('/discussions/mod-requests')">
|
|
||||||
Back to posts
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div v-if="loading" class="flex items-center justify-center py-12">
|
|
||||||
<p class="text-muted-foreground">Loading...</p>
|
|
||||||
</div>
|
|
||||||
<div v-else-if="error" class="text-red-500">{{ error }}</div>
|
|
||||||
<div v-else-if="post" class="space-y-6">
|
|
||||||
<div class="flex items-center gap-3">
|
|
||||||
<Badge :variant="post.is_open ? 'secondary' : 'outline'">
|
|
||||||
{{ post.is_open ? 'Open' : 'Locked' }}
|
|
||||||
</Badge>
|
|
||||||
</div>
|
|
||||||
<div class="border rounded-lg p-6 bg-muted/50">
|
|
||||||
<h2 class="text-2xl font-semibold mb-2">{{ post.content.mod_title }}</h2>
|
|
||||||
<p class="text-sm text-muted-foreground mb-4"><a :href="post.content.mod_link" target="_blank"
|
|
||||||
class="text-primary underline">{{ post.content.mod_link }}</a></p>
|
|
||||||
<div class="space-y-4">
|
|
||||||
<div>
|
|
||||||
<h3 class="font-medium">Description</h3>
|
|
||||||
<p>{{ post.content.description }}</p>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<h3 class="font-medium">Reason</h3>
|
|
||||||
<p>{{ post.content.reason }}</p>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<h3 class="font-medium">Tested?</h3>
|
|
||||||
<p>{{ post.content.confirmed_tested ? 'Yes' : 'No' }}</p>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<h3 class="font-medium">Detrimental Effects</h3>
|
|
||||||
<p>{{ post.content.detrimental_effects }}</p>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<h3 class="font-medium">Keybind Conflicts</h3>
|
|
||||||
<p>{{ post.content.keybind_conflicts || 'None' }}</p>
|
|
||||||
</div>
|
|
||||||
<div v-if="post.content.special_considerations">
|
|
||||||
<h3 class="font-medium">Additional Notes</h3>
|
|
||||||
<p>{{ post.content.special_considerations }}</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- discussion placeholder -->
|
|
||||||
<CommentThread :parent-id="post.id" :comments="post.comments" @comments-updated="post.comments = $event" />
|
|
||||||
|
|
||||||
</div>
|
|
||||||
<div v-else>
|
|
||||||
<p class="text-muted-foreground">Unable to locate this mod request.</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
@@ -227,6 +227,9 @@ onMounted(() => {
|
|||||||
/* Ensure the calendar fills the container properly */
|
/* Ensure the calendar fills the container properly */
|
||||||
:global(.fc) {
|
:global(.fc) {
|
||||||
height: 100% !important;
|
height: 100% !important;
|
||||||
|
--fc-page-bg-color: transparent;
|
||||||
|
--fc-neutral-bg-color: color-mix(in srgb, var(--color-foreground) 8%, transparent);
|
||||||
|
--fc-neutral-text-color: var(--color-muted-foreground);
|
||||||
--fc-border-color: var(--color-border);
|
--fc-border-color: var(--color-border);
|
||||||
--fc-button-bg-color: transparent;
|
--fc-button-bg-color: transparent;
|
||||||
--fc-button-border-color: var(--color-border);
|
--fc-button-border-color: var(--color-border);
|
||||||
@@ -299,6 +302,7 @@ onMounted(() => {
|
|||||||
:global(.fc .fc-scrollgrid td),
|
:global(.fc .fc-scrollgrid td),
|
||||||
:global(.fc .fc-scrollgrid th) {
|
:global(.fc .fc-scrollgrid th) {
|
||||||
border-color: var(--color-border);
|
border-color: var(--color-border);
|
||||||
|
background: var(--fc-page-bg-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------- Built-in toolbar (if you keep it) ---------- */
|
/* ---------- Built-in toolbar (if you keep it) ---------- */
|
||||||
@@ -346,9 +350,7 @@ onMounted(() => {
|
|||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
:global(#app > div > div.flex-1.min-h-0 > div > div > div > div.fc.fc-media-screen.fc-direction-ltr.fc-theme-standard > div.fc-view-harness.fc-view-harness-passive > div > table > thead > tr > th) {
|
|
||||||
background-color: transparent;
|
|
||||||
}
|
|
||||||
:global(.fc .fc-daygrid-day-top) {
|
:global(.fc .fc-daygrid-day-top) {
|
||||||
padding: 8px 8px 0 8px;
|
padding: 8px 8px 0 8px;
|
||||||
}
|
}
|
||||||
|
|||||||
52
ui/src/pages/DeveloperTools.vue
Normal file
52
ui/src/pages/DeveloperTools.vue
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import Button from '@/components/ui/button/Button.vue';
|
||||||
|
import { bustUserCache } from '@/api/member';
|
||||||
|
import type { UserCacheBustResult } from '@shared/types/member';
|
||||||
|
import { ref } from 'vue';
|
||||||
|
|
||||||
|
const loading = ref(false);
|
||||||
|
const result = ref<UserCacheBustResult | null>(null);
|
||||||
|
const error = ref<string | null>(null);
|
||||||
|
|
||||||
|
async function onBustUserCache() {
|
||||||
|
loading.value = true;
|
||||||
|
error.value = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
result.value = await bustUserCache();
|
||||||
|
} catch (err) {
|
||||||
|
result.value = null;
|
||||||
|
error.value = err instanceof Error ? err.message : 'Failed to bust user cache';
|
||||||
|
} finally {
|
||||||
|
loading.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="max-w-3xl mx-auto pt-10 px-4">
|
||||||
|
<h1 class="scroll-m-20 text-2xl font-semibold tracking-tight">Developer Tools</h1>
|
||||||
|
<p class="mt-2 text-sm text-muted-foreground">
|
||||||
|
Use this page to recover from stale in-memory authentication data after manual database changes.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div class="mt-6 rounded-lg border p-5 bg-card">
|
||||||
|
<p class="font-medium">Server User Cache</p>
|
||||||
|
<p class="text-sm text-muted-foreground mt-1">
|
||||||
|
This clears the API server's cached user session data so the next request reloads from the database.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div class="mt-4 flex items-center gap-3">
|
||||||
|
<Button :disabled="loading" @click="onBustUserCache">
|
||||||
|
{{ loading ? 'Busting Cache...' : 'Bust User Cache' }}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p v-if="result" class="mt-4 text-sm text-green-700">
|
||||||
|
Cache busted successfully. Cleared {{ result.clearedEntries }} entr{{ result.clearedEntries === 1 ? 'y' : 'ies' }} at
|
||||||
|
{{ new Date(result.bustedAt).toLocaleString() }}.
|
||||||
|
</p>
|
||||||
|
<p v-if="error" class="mt-4 text-sm text-red-700">{{ error }}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
<script setup lang="ts">
|
|
||||||
import { ref } from 'vue';
|
|
||||||
import Button from '@/components/ui/button/Button.vue';
|
|
||||||
import ModRequestForm from '@/components/modRequests/ModRequestForm.vue';
|
|
||||||
import ModRequestList from '@/components/modRequests/ModRequestList.vue';
|
|
||||||
|
|
||||||
const showForm = ref(false);
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<div class="max-w-[80rem] mt-5 mx-auto px-2 lg:px-20 w-full">
|
|
||||||
<!-- Header - always visible -->
|
|
||||||
<div class="mb-8">
|
|
||||||
<h1 class="scroll-m-20 text-3xl font-semibold tracking-tight mb-2">Mod Requests</h1>
|
|
||||||
<p class="text-muted-foreground">Submit and manage mod requests for the community</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- List View -->
|
|
||||||
<template v-if="!showForm">
|
|
||||||
<Button @click="showForm = true" class="mb-6">
|
|
||||||
New Request
|
|
||||||
</Button>
|
|
||||||
<ModRequestList></ModRequestList>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<!-- Form View -->
|
|
||||||
<template v-else>
|
|
||||||
<ModRequestForm class="mb-8" @close="showForm = false" @submit="(id) => $router.push(`/discussions/mod-requests/${id}`)"></ModRequestForm>
|
|
||||||
|
|
||||||
</template>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
@@ -32,6 +32,9 @@
|
|||||||
import Spinner from "@/components/ui/spinner/Spinner.vue";
|
import Spinner from "@/components/ui/spinner/Spinner.vue";
|
||||||
import DischargeMember from "@/components/members/DischargeMember.vue";
|
import DischargeMember from "@/components/members/DischargeMember.vue";
|
||||||
import MemberCard from "@/components/members/MemberCard.vue";
|
import MemberCard from "@/components/members/MemberCard.vue";
|
||||||
|
import { useMemberDirectory } from "@/stores/memberDirectory";
|
||||||
|
import { Discharge } from "@shared/schemas/dischargeSchema";
|
||||||
|
import TransferMember from "@/components/members/TransferMember.vue";
|
||||||
|
|
||||||
// --- State ---
|
// --- State ---
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
@@ -139,25 +142,41 @@
|
|||||||
|
|
||||||
//discharge form logic
|
//discharge form logic
|
||||||
const isDischargeOpen = ref(false)
|
const isDischargeOpen = ref(false)
|
||||||
const targetMember = ref(null)
|
const isTransferOpen = ref(false)
|
||||||
|
const targetMember = ref<Member | null>(null)
|
||||||
|
|
||||||
function openDischargeModal(member: Member) {
|
function openDischargeModal(member: Member) {
|
||||||
targetMember.value = member
|
targetMember.value = member
|
||||||
isDischargeOpen.value = true
|
isDischargeOpen.value = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function openTransferModal(member: Member) {
|
||||||
|
targetMember.value = member
|
||||||
|
isTransferOpen.value = true
|
||||||
|
}
|
||||||
|
|
||||||
async function onSuspend(member: Member) {
|
async function onSuspend(member: Member) {
|
||||||
await suspendMember(member.member_id);
|
await suspendMember(member.member_id);
|
||||||
await fetchMembers();
|
await fetchMembers();
|
||||||
|
memberCache.invalidateMember(member.member_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function onUnsuspend(member: Member) {
|
async function onUnsuspend(member: Member) {
|
||||||
await unsuspendMember(member.member_id);
|
await unsuspendMember(member.member_id);
|
||||||
await fetchMembers();
|
await fetchMembers();
|
||||||
|
memberCache.invalidateMember(member.member_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleDischargeSuccess(data) {
|
const memberCache = useMemberDirectory();
|
||||||
|
|
||||||
|
function handleDischargeSuccess(value: { data: Discharge }) {
|
||||||
fetchMembers();
|
fetchMembers();
|
||||||
|
memberCache.invalidateMember(value.data.userID);
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleTransferSuccess(value: { memberId: number; unitId: number; rankId: number; reason: string }) {
|
||||||
|
fetchMembers();
|
||||||
|
memberCache.invalidateMember(value.memberId);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -165,6 +184,8 @@
|
|||||||
<div>
|
<div>
|
||||||
<DischargeMember v-model:open="isDischargeOpen" :member="targetMember" @discharged="handleDischargeSuccess">
|
<DischargeMember v-model:open="isDischargeOpen" :member="targetMember" @discharged="handleDischargeSuccess">
|
||||||
</DischargeMember>
|
</DischargeMember>
|
||||||
|
<TransferMember v-model:open="isTransferOpen" :member="targetMember" @transferred="handleTransferSuccess">
|
||||||
|
</TransferMember>
|
||||||
<div class="mx-auto max-w-7xl w-full py-10 px-4">
|
<div class="mx-auto max-w-7xl w-full py-10 px-4">
|
||||||
<div class="flex flex-col gap-2">
|
<div class="flex flex-col gap-2">
|
||||||
<div class="flex flex-col md:flex-row md:items-center justify-between gap-4">
|
<div class="flex flex-col md:flex-row md:items-center justify-between gap-4">
|
||||||
@@ -245,7 +266,8 @@
|
|||||||
<TableCell>{{ member.rank }}</TableCell>
|
<TableCell>{{ member.rank }}</TableCell>
|
||||||
<TableCell>{{ member.unit }}</TableCell>
|
<TableCell>{{ member.unit }}</TableCell>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<Badge variant="outline" class="capitalize font-normal">{{ MemberState[member.member_state] }}</Badge>
|
<Badge variant="outline" class="capitalize font-normal">{{
|
||||||
|
MemberState[member.member_state] }}</Badge>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<Badge v-if="member.loa_until" variant="secondary"
|
<Badge v-if="member.loa_until" variant="secondary"
|
||||||
@@ -262,11 +284,17 @@
|
|||||||
<!-- <DropdownMenuItem @click="navigateToMember(member.member_id)">
|
<!-- <DropdownMenuItem @click="navigateToMember(member.member_id)">
|
||||||
View Profile
|
View Profile
|
||||||
</DropdownMenuItem> -->
|
</DropdownMenuItem> -->
|
||||||
<DropdownMenuItem @click="openDischargeModal(member)"
|
<DropdownMenuItem v-if="member.member_state === MemberState.Member"
|
||||||
|
@click="openTransferModal(member)">
|
||||||
|
Transfer Member
|
||||||
|
</DropdownMenuItem>
|
||||||
|
<DropdownMenuItem v-if="member.member_state !== MemberState.Discharged"
|
||||||
|
@click="openDischargeModal(member)"
|
||||||
class="text-destructive focus:bg-destructive focus:text-destructive-foreground font-medium">
|
class="text-destructive focus:bg-destructive focus:text-destructive-foreground font-medium">
|
||||||
Discharge Member
|
Discharge Member
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
<DropdownMenuItem v-if="member.member_state !== MemberState.Suspended" @click="onSuspend(member)"
|
<DropdownMenuItem v-if="member.member_state !== MemberState.Suspended"
|
||||||
|
@click="onSuspend(member)"
|
||||||
class="text-destructive focus:bg-destructive focus:text-destructive-foreground font-medium">
|
class="text-destructive focus:bg-destructive focus:text-destructive-foreground font-medium">
|
||||||
Suspend Member
|
Suspend Member
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
|
|||||||
@@ -28,20 +28,12 @@ const router = createRouter({
|
|||||||
{ path: '/trainingReport/new', component: () => import('@/pages/TrainingReport.vue'), meta: { requiresAuth: true, memberOnly: true } },
|
{ path: '/trainingReport/new', component: () => import('@/pages/TrainingReport.vue'), meta: { requiresAuth: true, memberOnly: true } },
|
||||||
{ path: '/trainingReport/:id', component: () => import('@/pages/TrainingReport.vue'), meta: { requiresAuth: true, memberOnly: true } },
|
{ path: '/trainingReport/:id', component: () => import('@/pages/TrainingReport.vue'), meta: { requiresAuth: true, memberOnly: true } },
|
||||||
|
|
||||||
//discussion routes
|
{ path: '/developer', component: () => import('@/pages/DeveloperTools.vue'), meta: { requiresAuth: true, memberOnly: true, roles: ['Dev'] } },
|
||||||
{
|
|
||||||
path: '/discussions',
|
|
||||||
meta: { requiresAuth: true, memberOnly: true },
|
|
||||||
children: [
|
|
||||||
{ path: 'mod-requests', component: () => import('@/pages/ModRequest.vue') },
|
|
||||||
{ path: 'mod-requests/:id', component: () => import('@/components/modRequests/ViewModRequest.vue') },
|
|
||||||
]
|
|
||||||
},
|
|
||||||
|
|
||||||
// ADMIN / STAFF ROUTES
|
// ADMIN / STAFF ROUTES
|
||||||
{
|
{
|
||||||
path: '/administration',
|
path: '/administration',
|
||||||
meta: { requiresAuth: true, memberOnly: true, roles: ['17th Administrator', '17th HQ', '17th Command'] },
|
meta: { requiresAuth: true, memberOnly: true, roles: ['17th Administrator', '17th HQ', '17th Command', '17th Recruiter'] },
|
||||||
children: [
|
children: [
|
||||||
{ path: 'applications', component: () => import('@/pages/ManageApplications.vue') },
|
{ path: 'applications', component: () => import('@/pages/ManageApplications.vue') },
|
||||||
{ path: 'applications/:id', component: () => import('@/pages/ManageApplications.vue') },
|
{ path: 'applications/:id', component: () => import('@/pages/ManageApplications.vue') },
|
||||||
|
|||||||
Reference in New Issue
Block a user