Skip to content

Commit

Permalink
Clear gang memberships prior to creating a new one
Browse files Browse the repository at this point in the history
  • Loading branch information
RussellLVP committed Jun 26, 2020
1 parent 3a9783c commit 78e2a58
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions javascript/features/gangs/gang_database.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,16 @@ const GANG_CREATE_QUERY = `
VALUES
(?, ?, ?)`;

// Query to clear prior memberships when joining a new gang.
const GANG_CLEAR_MEMBER_QUERY = `
UPDATE
users_gangs
SET
users_gangs.left_gang = NOW()
WHERE
users_gangs.user_id = ? AND
users_gangs.left_gang IS NULL`;

// Query to add a member to a given gang in the database.
const GANG_CREATE_MEMBER_QUERY = `
INSERT INTO
Expand Down Expand Up @@ -348,6 +358,7 @@ class GangDatabase {

gangId = results.insertId;

await server.database.query(GANG_CLEAR_MEMBER_QUERY, player.account.userId);
await server.database.query(
GANG_CREATE_MEMBER_QUERY, player.account.userId, results.insertId, 'Leader');

Expand Down Expand Up @@ -389,6 +400,7 @@ class GangDatabase {
const userId = player.account.userId;
const gangId = gang.id;

await server.database.query(GANG_CLEAR_MEMBER_QUERY, userId);
await server.database.query(GANG_CREATE_MEMBER_QUERY, userId, gangId, 'Member');
}

Expand Down

0 comments on commit 78e2a58

Please sign in to comment.