task agent validation: if agent is not in the crew, replace task agent with null
This commit is contained in:
@@ -62,9 +62,7 @@ const resolvers = {
|
||||
for (let task of body.tasks) {
|
||||
let agent = null;
|
||||
if (task.agent) {
|
||||
agent = await prisma.agent.findFirst({
|
||||
where: { id: task.agent },
|
||||
});
|
||||
agent = crew.find((a) => a.id === task.agent) ?? null;
|
||||
}
|
||||
tasks.push({
|
||||
...task,
|
||||
@@ -97,9 +95,7 @@ const resolvers = {
|
||||
for (let task of body.tasks) {
|
||||
let agent = null;
|
||||
if (task.agent) {
|
||||
agent = await prisma.agent.findFirst({
|
||||
where: { id: task.agent },
|
||||
});
|
||||
agent = crew.find((a) => a.id === task.agent) ?? null;
|
||||
}
|
||||
tasks.push({
|
||||
...task,
|
||||
|
||||
@@ -127,14 +127,23 @@ export default function MissionModal(props: {
|
||||
value: agent.id,
|
||||
}))}
|
||||
multiple
|
||||
value={tempMission.crew.map((agent) => agent.id!)}
|
||||
onValueChange={(event: any) => {
|
||||
const newValue = event.map((item: any) => item.value);
|
||||
const newCrew = agentsData.agents.filter(
|
||||
(agent: Agent) => newValue.includes(agent.id)
|
||||
);
|
||||
const newTasks = tempMission.tasks.map((task) => ({
|
||||
...task,
|
||||
agent:
|
||||
newCrew.find(
|
||||
(agent: Agent) => agent.id === task.agent?.id
|
||||
) ?? null,
|
||||
}));
|
||||
setTempMission((prevState) => ({
|
||||
...prevState!,
|
||||
crew: newCrew,
|
||||
tasks: newTasks,
|
||||
}));
|
||||
}}
|
||||
theme={selectTheme}
|
||||
@@ -208,8 +217,8 @@ export default function MissionModal(props: {
|
||||
{isEdit ? (
|
||||
<div>
|
||||
<MissionTaskEditor
|
||||
mission={mission!}
|
||||
agents={mission?.crew!}
|
||||
mission={tempMission!}
|
||||
agents={tempMission?.crew!}
|
||||
onMissionChange={(mission: Mission) => {
|
||||
setTempMission(mission);
|
||||
}}
|
||||
@@ -267,7 +276,7 @@ export default function MissionModal(props: {
|
||||
<TERipple rippleColor="light">
|
||||
<Button
|
||||
color="white"
|
||||
onClick={() => setShowModal(false)}
|
||||
onClick={() => setEdit(false)}
|
||||
placeholder={undefined}
|
||||
>
|
||||
Cancel
|
||||
@@ -282,6 +291,7 @@ export default function MissionModal(props: {
|
||||
handleUpdateMission(tempMission)
|
||||
.then(() => {
|
||||
setShowModal(false);
|
||||
setEdit(false);
|
||||
ReactSwal.fire({
|
||||
title: "Update Mission",
|
||||
text: "Mission updated successfully",
|
||||
|
||||
@@ -119,9 +119,17 @@ function NewMissionModal(props: {
|
||||
const newCrew = agentsData.agents.filter(
|
||||
(agent: Agent) => newValue.includes(agent.id)
|
||||
);
|
||||
const newTasks = tempMission.tasks.map((task) => ({
|
||||
...task,
|
||||
agent:
|
||||
newCrew.find(
|
||||
(agent: Agent) => agent.id === task.agent?.id
|
||||
) ?? null,
|
||||
}));
|
||||
setTempMission((prevState) => ({
|
||||
...prevState!,
|
||||
crew: newCrew,
|
||||
tasks: newTasks,
|
||||
}));
|
||||
}}
|
||||
theme={selectTheme}
|
||||
|
||||
Reference in New Issue
Block a user