Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edit ticket page #32

Merged
merged 28 commits into from
May 5, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
5535d46
basic edit ticket functionality
Val-Bustamante May 3, 2023
4ac1011
fixed edit and make ticket bugs
Val-Bustamante May 3, 2023
dc0c895
add owners in makeTicket functionality
Val-Bustamante May 3, 2023
751990f
fix adding owners bug
Val-Bustamante May 4, 2023
a4bd74a
add required to form fields
Val-Bustamante May 4, 2023
67659bc
change deadline to datetime object and add default values to edit tic…
Val-Bustamante May 4, 2023
05dbe71
fix default values in edit ticket form
Val-Bustamante May 4, 2023
62e272b
fix default value for deadline in edit form
Val-Bustamante May 4, 2023
1adc9b5
take out console.logs
Val-Bustamante May 4, 2023
c80ef26
fix default value for owners in edit Ticket form
Val-Bustamante May 4, 2023
2c8d1e0
merged changes in main into branch
Val-Bustamante May 4, 2023
8ba337c
fix filterResults to not add tickets twice
Val-Bustamante May 5, 2023
7c16c85
fix edit ticket form- name and description now fills in
Val-Bustamante May 5, 2023
78bfa41
fix error caused by seed file: refrence error
Val-Bustamante May 5, 2023
e114a6e
fix owners list editing rights
Val-Bustamante May 5, 2023
e17bf96
fix select bug in edit page
Val-Bustamante May 5, 2023
3c56436
add status change ability for admin in edit ticket
Val-Bustamante May 5, 2023
fd6ecba
Fixed bug where owners weren't being updated
bigguyhere May 5, 2023
782c9ef
Removed unecessary logging
bigguyhere May 5, 2023
7ce2f38
Made dates consistent with edit ticket date
bigguyhere May 5, 2023
c03275c
fix merge
Val-Bustamante May 5, 2023
2a75b2d
have default values in edit form not go away after an error occurs
Val-Bustamante May 5, 2023
a953e39
Fixed error where using same date for a deadline that is already past…
bigguyhere May 5, 2023
c696bb0
Merge branch 'edit-ticket' of https://github.com/MAPReiff/Tikit into …
bigguyhere May 5, 2023
337863a
Fixed issues with date and deleting owners
bigguyhere May 5, 2023
5588390
Removed some logging
bigguyhere May 5, 2023
051f8d7
Fixed redundant ticket getting
bigguyhere May 5, 2023
a16cd6c
Merge branch 'main' into edit-ticket
bigguyhere May 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 additions & 4 deletions data/tickets.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ const create = async (
throw "Error: could not update user successfully!";
}

await updateOwners(userCollection, insertInfo.insertedId, owners);
await updateOwners(userCollection, insertInfo.insertedId, owners, owners);

const newId = insertInfo.insertedId.toString();

Expand Down Expand Up @@ -329,6 +329,7 @@ const update = async (
tags: tags,
comments: curTicket.comments,
};

const objID = new ObjectId(id);
const updatedInfo = await ticketCollection.findOneAndUpdate(
{ _id: objID },
Expand All @@ -340,8 +341,9 @@ const update = async (
throw "Error: could not update ticket successfully!";
}


const userCollection = await users();
await updateOwners(userCollection, objID, owners);
await updateOwners(userCollection, objID, owners, oldOwners);

return toStringify(updatedInfo.value);
};
Expand Down Expand Up @@ -391,10 +393,35 @@ const filterResults = async (inputTickets, isAdmin, userID) => {
return returnVal;
}

const updateOwners = async (userCollection, ticketID, owners) => {
const updateOwners = async (userCollection, ticketID, newOwners, oldOwners) => {

if(newOwners && oldOwners){
var removeOldOwners;

if(oldOwners.length > newOwners.length){
var removeOwners = oldOwners.filter(x => !newOwners.includes(x));
for (let owner of removeOwners) {
console.log("removing owners");
removeOldOwners = await userCollection.findOneAndUpdate(
{ _id: new ObjectId(owner) },
{
$pull: {
ticketsBeingWorkedOn: ticketID,
},
},
{ returnDocument: "after" }
);

if (removeOldOwners.lastErrorObject.n === 0) {
throw "Error: could not update user successfully!";
}
}
}
}

let updatedInfo;

for (let owner of owners) {
for (let owner of newOwners) {
updatedInfo = await userCollection.findOneAndUpdate(
{ _id: new ObjectId(owner) },
{
Expand Down
19 changes: 18 additions & 1 deletion routes/tickets.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,24 @@ router

} catch (e) {
// render form with 400 code
res.status(400).render("editTicket", { title: "Edit Ticket", error: `${e}`, _id: req.params.id, users:users});
res.status(400).render("editTicket", {
title: "Edit Ticket",
error: `${e}`,
_id: req.params.id,
users:users,
title: ticket.name,
user_id: req.session.user._id,
name: ticket.name,
description: ticket.description,
status: ticket.status,
priority: ticket.priority,
created: !ticket.createdOn ? "N/A" : dateFormatter(ticket.createdOn),
deadline: !ticket.deadline ? "N/A" : new Date(ticket.deadline).toISOString().substring(0, 10),
customer: await userData.get(ticket.customerID.toString()),
owners: ticket.owners,
category: ticket.category,
role: req.session.user.role,
tag: ticket.tags});
}

});
Expand Down