-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Start of Admin Panel User Search New House * Removed Homes * user search and admin api made * pulling user info for admin * Chat history by user * Final Chat history by user * WIP donor role assignments * Auto stash before merge of "donor-admin" and "CybertownRevival/master" * Auto stash before merge of "donor-admin" and "CybertownRevival/master" * Setting Donor Levels * Review Submission * Quick Fixes * Fixes as Requested * Minor Donor Fix When going from donor to None, had to refresh before showing change, now shows on submitting.
- Loading branch information
Showing
73 changed files
with
29,994 additions
and
15,529 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import {knex, Knex} from 'knex'; | ||
|
||
const COLLATE = 'utf8mb4_unicode_ci'; | ||
function applyCommon(table: Knex.CreateTableBuilder) { | ||
table.collate(COLLATE); | ||
table.increments('id').primary(); | ||
table.timestamps(false, true); | ||
} | ||
|
||
export async function up(knex: Knex): Promise<void> { | ||
if (!await knex.schema.hasTable('ban')){ | ||
await knex.schema.createTable('ban', (table) => { | ||
console.log('Creating ban table'); | ||
applyCommon(table); | ||
|
||
table.integer('status') | ||
.defaultTo(1); | ||
|
||
table.integer('ban_member_id') | ||
.notNullable(); | ||
|
||
table.date('end_date') | ||
.notNullable(); | ||
|
||
table.enu('type', ['jail', 'full']) | ||
.defaultTo('jail') | ||
.notNullable(); | ||
|
||
table.integer('assigner_member_id') | ||
.notNullable(); | ||
|
||
table.text('reason').notNullable(); | ||
}); | ||
} | ||
} | ||
|
||
|
||
export async function down(knex: Knex): Promise<void> { | ||
if (await knex.schema.hasTable('ban')){ | ||
await knex.schema.dropTable('ban'); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Knex } from 'knex'; | ||
|
||
const donorData = require('./../seed_data/donor_data.json'); | ||
|
||
export async function seed(knex: Knex): Promise<void> { | ||
console.log('Seeding donor data'); | ||
|
||
await knex('role').insert(donorData); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
[ | ||
{ | ||
"name": "Supporter", | ||
"income_xp": 0, | ||
"income_cc": 0 | ||
}, | ||
{ | ||
"name": "Advocate", | ||
"income_xp": 0, | ||
"income_cc": 0 | ||
}, | ||
{ | ||
"name": "Devotee", | ||
"income_xp": 0, | ||
"income_cc": 0 | ||
}, | ||
{ | ||
"name": "Champion", | ||
"income_xp": 0, | ||
"income_cc": 0 | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
import {Request, Response} from 'express'; | ||
import { Container } from 'typedi'; | ||
|
||
import { AdminService, MemberService } from '../services'; | ||
|
||
class AdminController { | ||
constructor(private adminService: AdminService, private memberService: MemberService) {} | ||
|
||
public async addBan(request: Request, response: Response): Promise<any> { | ||
const session = this.memberService.decryptSession(request, response); | ||
if (!session) return; | ||
const admin = await this.memberService.canAdmin(session.id); | ||
if (admin) { | ||
try { | ||
await this.adminService.addBan( | ||
request.body.ban_member_id, | ||
request.body.time_frame, | ||
request.body.type, | ||
session.id, | ||
request.body.reason, | ||
); | ||
response.status(200).json({message: 'Ban added successfully'}); | ||
} catch (error) { | ||
console.log(error); | ||
response.status(400).json({error}); | ||
} | ||
} else { | ||
response.status(403).json({message: 'Access Denied'}); | ||
} | ||
} | ||
|
||
public async addDonor(request: Request, response: Response): Promise<void>{ | ||
const session = this.memberService.decryptSession(request, response); | ||
if (!session) return; | ||
const accessLevel = await this.memberService.getAccessLevel(session.id); | ||
if (accessLevel === 'admin') { | ||
try { | ||
await this.adminService.addDonor( | ||
request.body.member_id, | ||
request.body.level, | ||
); | ||
response.status(200).json({message: 'Donor added successfully'}); | ||
} catch (e) { | ||
console.log(e); | ||
response.status(400).json({error: 'Error adding donor'}); | ||
} | ||
} else { | ||
response.status(403).json({error: 'Access Denied'}); | ||
} | ||
} | ||
|
||
public async getBanHistory(request: Request, response: Response): Promise<any> { | ||
const session = this.memberService.decryptSession(request, response); | ||
if (!session) return; | ||
const admin = await this.memberService.canAdmin(session.id); | ||
if (admin) { | ||
try { | ||
const banHistory = await this.adminService | ||
.getBanHistory(Number(request.query.ban_member_id.toString())); | ||
response.status(200).json({banHistory}); | ||
} catch (error) { | ||
console.log(error); | ||
response.status(400).json({error}); | ||
} | ||
} else { | ||
response.status(403).json({message: 'Access Denied'}); | ||
} | ||
} | ||
|
||
public async deleteBan(request: Request, response: Response): Promise<void> { | ||
const session = this.memberService.decryptSession(request, response); | ||
if (!session) return; | ||
const admin = await this.memberService.canAdmin(session.id); | ||
if (admin) { | ||
try { | ||
const banId = Number(request.body.banId); | ||
const reason = request.body.banReason; | ||
const deleteBy = await this.memberService.getMemberInfoPublic(session.id); | ||
const updateReason = `${reason} (Deleted by ${deleteBy.username})`; | ||
await this.adminService.deleteBan(banId, updateReason); | ||
response.status(200).json({message: 'Ban deleted successfully'}); | ||
} catch (error) { | ||
console.log(error); | ||
response.status(400).json({error}); | ||
} | ||
} else { | ||
response.status(403).json({message: 'Access Denied'}); | ||
} | ||
} | ||
|
||
public async getDonor(request: Request, response: Response): Promise<string> { | ||
const session = this.memberService.decryptSession(request, response); | ||
if (!session) return; | ||
const accessLevel = await this.memberService.getAccessLevel(session.id); | ||
if (accessLevel === 'admin') { | ||
const currentLevel = await this | ||
.adminService | ||
.getDonor(Number(request.query.memberId)); | ||
response.status(200).json({donorLevel: currentLevel}); | ||
} else { | ||
response.status(403).json({error: 'Access Denied'}); | ||
} | ||
} | ||
|
||
public async searchUsers(request: Request, response: Response): Promise<any> { | ||
const session = this.memberService.decryptSession(request, response); | ||
if (!session) return; | ||
const admin = await this.memberService.canAdmin(session.id); | ||
if (admin) { | ||
try { | ||
const results = await this.adminService.searchUsers( | ||
request.query.search.toString(), | ||
Number.parseInt(request.query.limit.toString()), | ||
Number.parseInt(request.query.offset.toString()), | ||
); | ||
response.status(200).json({results}); | ||
} catch (error) { | ||
console.log(error); | ||
response.status(400).json({error}); | ||
} | ||
} else { | ||
response.status(403).json({message: 'Access Denied'}); | ||
} | ||
} | ||
|
||
public async searchUserChat(request: Request, response: Response): Promise<any> { | ||
const session = this.memberService.decryptSession(request, response); | ||
if (!session) return; | ||
const admin = await this.memberService.canAdmin(session.id); | ||
if (admin) { | ||
try { | ||
const results = await this.adminService.searchUserChat( | ||
request.query.search.toString(), | ||
Number.parseInt(request.query.user.toString()), | ||
Number.parseInt(request.query.limit.toString()), | ||
Number.parseInt(request.query.offset.toString()), | ||
); | ||
response.status(200).json({results}); | ||
} catch (error) { | ||
console.log(error); | ||
response.status(400).json({error}); | ||
} | ||
} else { | ||
response.status(403).json({message: 'Access Denied'}); | ||
} | ||
} | ||
} | ||
|
||
const adminService = Container.get(AdminService); | ||
const memberService = Container.get(MemberService); | ||
export const adminController = new AdminController(adminService, memberService); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.