import express from 'express';
import { permissionSystem } from '../../../../features/permission';

export async function GroupGrantsChanged(req: express.Request, res: express.Response): Promise<express.Response<any, Record<string, any>>> {
    if (!req.params.groupId) {
        res.status(400).send('Missing parameter');
    }

    if (!Number(req.params.groupId)) {
        res.status(500).send('Unable to parse given parameter');
    }

    const groupId = Number(req.params.groupId);
    for (const player of mp.players.toArray()) {
        if (player.account?.groups.find((g) => g.id === groupId)) {
            await permissionSystem.loadPlayerPermissions(player, true);
        }
    }
    return res.sendStatus(200);
}
