From a479b3194a680f7f10f142d6f0ae5537e892a771 Mon Sep 17 00:00:00 2001 From: RoshanKarthikRajesh Date: Tue, 2 Jul 2024 21:49:19 -0400 Subject: [PATCH 1/3] Edited resource.ts to allow read/write when authenticated. --- amplify/data/resource.ts | 2 +- package-lock.json | 145 +++++++++++++++++++++++++++++++- package.json | 3 +- src/app/(home)/pathways/page.js | 2 +- src/app/(home)/tasks/page.js | 40 ++++++--- 5 files changed, 173 insertions(+), 19 deletions(-) diff --git a/amplify/data/resource.ts b/amplify/data/resource.ts index 84e68e7..f526cb5 100644 --- a/amplify/data/resource.ts +++ b/amplify/data/resource.ts @@ -81,7 +81,7 @@ const schema = a.schema({ important: a.boolean(), done: a.boolean(), }) - .authorization((allow) => [allow.guest()]), + .authorization((allow) => [allow.authenticated()]), }); export type Schema = ClientSchema; diff --git a/package-lock.json b/package-lock.json index 489230b..00bcbc3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -26,7 +26,8 @@ "mui-nested-menu": "^3.3.0", "next": "latest", "react": "latest", - "react-dom": "latest" + "react-dom": "latest", + "uuid": "^10.0.0" }, "devDependencies": { "@aws-amplify/backend": "^1.0.3", @@ -443,6 +444,19 @@ "node": ">=14.0.0" } }, + "node_modules/@aws-amplify/api-graphql/node_modules/uuid": { + "version": "9.0.1", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz", + "integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==", + "funding": [ + "https://github.com/sponsors/broofa", + "https://github.com/sponsors/ctavan" + ], + "license": "MIT", + "bin": { + "uuid": "dist/bin/uuid" + } + }, "node_modules/@aws-amplify/api-rest": { "version": "4.0.35", "resolved": "https://registry.npmjs.org/@aws-amplify/api-rest/-/api-rest-4.0.35.tgz", @@ -834,6 +848,19 @@ "node": ">=14.0.0" } }, + "node_modules/@aws-amplify/core/node_modules/uuid": { + "version": "9.0.1", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz", + "integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==", + "funding": [ + "https://github.com/sponsors/broofa", + "https://github.com/sponsors/ctavan" + ], + "license": "MIT", + "bin": { + "uuid": "dist/bin/uuid" + } + }, "node_modules/@aws-amplify/data-construct": { "version": "1.8.5", "resolved": "https://registry.npmjs.org/@aws-amplify/data-construct/-/data-construct-1.8.5.tgz", @@ -2736,6 +2763,20 @@ "zod": "^3.22.2" } }, + "node_modules/@aws-amplify/platform-core/node_modules/uuid": { + "version": "9.0.1", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz", + "integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==", + "dev": true, + "funding": [ + "https://github.com/sponsors/broofa", + "https://github.com/sponsors/ctavan" + ], + "license": "MIT", + "bin": { + "uuid": "dist/bin/uuid" + } + }, "node_modules/@aws-amplify/plugin-types": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/@aws-amplify/plugin-types/-/plugin-types-1.0.0.tgz", @@ -3353,6 +3394,20 @@ "node": ">=16.0.0" } }, + "node_modules/@aws-sdk/client-amplifyuibuilder/node_modules/uuid": { + "version": "9.0.1", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz", + "integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==", + "dev": true, + "funding": [ + "https://github.com/sponsors/broofa", + "https://github.com/sponsors/ctavan" + ], + "license": "MIT", + "bin": { + "uuid": "dist/bin/uuid" + } + }, "node_modules/@aws-sdk/client-appsync": { "version": "3.600.0", "resolved": "https://registry.npmjs.org/@aws-sdk/client-appsync/-/client-appsync-3.600.0.tgz", @@ -3516,6 +3571,20 @@ "node": ">=16.0.0" } }, + "node_modules/@aws-sdk/client-cloudformation/node_modules/uuid": { + "version": "9.0.1", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz", + "integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==", + "dev": true, + "funding": [ + "https://github.com/sponsors/broofa", + "https://github.com/sponsors/ctavan" + ], + "license": "MIT", + "bin": { + "uuid": "dist/bin/uuid" + } + }, "node_modules/@aws-sdk/client-cognito-identity": { "version": "3.600.0", "resolved": "https://registry.npmjs.org/@aws-sdk/client-cognito-identity/-/client-cognito-identity-3.600.0.tgz", @@ -5138,6 +5207,19 @@ "node": ">=14.0.0" } }, + "node_modules/@aws-sdk/client-firehose/node_modules/uuid": { + "version": "9.0.1", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz", + "integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==", + "funding": [ + "https://github.com/sponsors/broofa", + "https://github.com/sponsors/ctavan" + ], + "license": "MIT", + "bin": { + "uuid": "dist/bin/uuid" + } + }, "node_modules/@aws-sdk/client-iam": { "version": "3.338.0", "resolved": "https://registry.npmjs.org/@aws-sdk/client-iam/-/client-iam-3.338.0.tgz", @@ -6748,6 +6830,19 @@ "node": ">=14.0.0" } }, + "node_modules/@aws-sdk/client-kinesis/node_modules/uuid": { + "version": "9.0.1", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz", + "integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==", + "funding": [ + "https://github.com/sponsors/broofa", + "https://github.com/sponsors/ctavan" + ], + "license": "MIT", + "bin": { + "uuid": "dist/bin/uuid" + } + }, "node_modules/@aws-sdk/client-lambda": { "version": "3.338.0", "resolved": "https://registry.npmjs.org/@aws-sdk/client-lambda/-/client-lambda-3.338.0.tgz", @@ -8281,6 +8376,19 @@ "node": ">=14.0.0" } }, + "node_modules/@aws-sdk/client-personalize-events/node_modules/uuid": { + "version": "9.0.1", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz", + "integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==", + "funding": [ + "https://github.com/sponsors/broofa", + "https://github.com/sponsors/ctavan" + ], + "license": "MIT", + "bin": { + "uuid": "dist/bin/uuid" + } + }, "node_modules/@aws-sdk/client-rds": { "version": "3.338.0", "resolved": "https://registry.npmjs.org/@aws-sdk/client-rds/-/client-rds-3.338.0.tgz", @@ -9007,6 +9115,20 @@ "node": ">=16.0.0" } }, + "node_modules/@aws-sdk/client-ssm/node_modules/uuid": { + "version": "9.0.1", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz", + "integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==", + "dev": true, + "funding": [ + "https://github.com/sponsors/broofa", + "https://github.com/sponsors/ctavan" + ], + "license": "MIT", + "bin": { + "uuid": "dist/bin/uuid" + } + }, "node_modules/@aws-sdk/client-sso": { "version": "3.598.0", "resolved": "https://registry.npmjs.org/@aws-sdk/client-sso/-/client-sso-3.598.0.tgz", @@ -15450,6 +15572,20 @@ "node": ">=16.0.0" } }, + "node_modules/@smithy/middleware-retry/node_modules/uuid": { + "version": "9.0.1", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz", + "integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==", + "dev": true, + "funding": [ + "https://github.com/sponsors/broofa", + "https://github.com/sponsors/ctavan" + ], + "license": "MIT", + "bin": { + "uuid": "dist/bin/uuid" + } + }, "node_modules/@smithy/middleware-serde": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/@smithy/middleware-serde/-/middleware-serde-3.0.2.tgz", @@ -24009,13 +24145,14 @@ "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==" }, "node_modules/uuid": { - "version": "9.0.1", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz", - "integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==", + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-10.0.0.tgz", + "integrity": "sha512-8XkAphELsDnEGrDxUOHB3RGvXz6TeuYSGEZBOjtTtPm2lwhGBjLgOzLHB63IUWfBpNucQjND6d3AOudO+H3RWQ==", "funding": [ "https://github.com/sponsors/broofa", "https://github.com/sponsors/ctavan" ], + "license": "MIT", "bin": { "uuid": "dist/bin/uuid" } diff --git a/package.json b/package.json index 9dc35a1..22075e7 100755 --- a/package.json +++ b/package.json @@ -31,7 +31,8 @@ "mui-nested-menu": "^3.3.0", "next": "latest", "react": "latest", - "react-dom": "latest" + "react-dom": "latest", + "uuid": "^10.0.0" }, "devDependencies": { "@aws-amplify/backend": "^1.0.3", diff --git a/src/app/(home)/pathways/page.js b/src/app/(home)/pathways/page.js index 16f38da..92aa1c5 100755 --- a/src/app/(home)/pathways/page.js +++ b/src/app/(home)/pathways/page.js @@ -105,7 +105,7 @@ export default function PathwaysPage() { {/*Popup Dialog*/} + { + client.models.Tasks.list().then(({ data, errors }) => + { + errors ? console.error(errors) : + setTasks(data); + }); + } + + useEffect(() => fetchTasks(), []); + const handleTaskDelete = (id) => { setTasks(tasks.filter((t) => t.id !== id)); console.log('deleted'); } - const handleTaskAddClick = () => + const handleTaskAddClick = async () => { - const newTask = { - id: tasks.length, + + const { errors, data } = await client.models.Tasks.create({ + TaskId: uuidv4(), title: "", details: "", - date: "", + date: null, important: false, done: false - }; - setTasks([...tasks, newTask]); + }) + errors ? console.error(errors) : + setTasks([...tasks, data]); console.log('added a task'); } From 05b611044c8d5272727a27b7ca039f0e8512c0e1 Mon Sep 17 00:00:00 2001 From: RoshanKarthikRajesh Date: Wed, 3 Jul 2024 12:12:21 -0400 Subject: [PATCH 2/3] Backend delete functionality --- src/app/(home)/tasks/page.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/app/(home)/tasks/page.js b/src/app/(home)/tasks/page.js index b8a6f2f..8b594d3 100755 --- a/src/app/(home)/tasks/page.js +++ b/src/app/(home)/tasks/page.js @@ -42,15 +42,16 @@ export default function Lists () useEffect(() => fetchTasks(), []); - const handleTaskDelete = (id) => + const handleTaskDelete = async (id) => { - setTasks(tasks.filter((t) => t.id !== id)); + const { data, errors } = await client.models.Tasks.delete({ TaskId: id }); + errors ? console.error(errors) : + fetchTasks(); console.log('deleted'); } const handleTaskAddClick = async () => { - const { errors, data } = await client.models.Tasks.create({ TaskId: uuidv4(), title: "", @@ -60,7 +61,7 @@ export default function Lists () done: false }) errors ? console.error(errors) : - setTasks([...tasks, data]); + fetchTasks(); console.log('added a task'); } @@ -73,8 +74,8 @@ export default function Lists () { return ( (index === tasks.length - 1) ? - handleTaskDelete(t.id)} /> - : handleTaskDelete(t.id)} /> + + : ) }) } From 584e4ffb96034156ab0ff8b7cf811260722d2562 Mon Sep 17 00:00:00 2001 From: RoshanKarthikRajesh Date: Fri, 5 Jul 2024 11:31:38 -0400 Subject: [PATCH 3/3] Adding and deleting tasks works perfectly. Need to work on updating the fields. --- amplify/data/resource.ts | 5 +---- src/app/(home)/tasks/page.js | 8 +++----- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/amplify/data/resource.ts b/amplify/data/resource.ts index f526cb5..3288af4 100644 --- a/amplify/data/resource.ts +++ b/amplify/data/resource.ts @@ -15,7 +15,6 @@ const schema = a.schema({ courses: a.hasMany("Course", "organizationId"), pathways: a.hasMany("Pathway", "organizationId"), admins: a.hasMany("User", "organizationId"), - tasks: a.hasMany("Tasks", "organizationId"), }) .authorization((allow) => [allow.guest()]), User: a @@ -70,11 +69,9 @@ const schema = a.schema({ .authorization((allow) => [allow.guest()]), Tasks: a .model({ - TaskId: a.id(), userId: a.id(), user: a.belongsTo("User", "userId"), - organizationId: a.id(), - organization: a.belongsTo("Organization", "organizationId"), + TaskId: a.id(), title: a.string(), details: a.string(), date: a.date(), diff --git a/src/app/(home)/tasks/page.js b/src/app/(home)/tasks/page.js index 8b594d3..dbe7cd7 100755 --- a/src/app/(home)/tasks/page.js +++ b/src/app/(home)/tasks/page.js @@ -20,7 +20,6 @@ import TaskHeaderCard from "@/components/Cards/TaskHeaderCard"; import TaskCard from "@/components/Cards/TaskCard"; import { Box } from "@mui/material"; -import { v4 as uuidv4 } from 'uuid'; export default function Lists () { const client = generateClient({ authMode: 'userPool' }); @@ -44,7 +43,7 @@ export default function Lists () const handleTaskDelete = async (id) => { - const { data, errors } = await client.models.Tasks.delete({ TaskId: id }); + const { data, errors } = await client.models.Tasks.delete({ id: id }); errors ? console.error(errors) : fetchTasks(); console.log('deleted'); @@ -53,7 +52,6 @@ export default function Lists () const handleTaskAddClick = async () => { const { errors, data } = await client.models.Tasks.create({ - TaskId: uuidv4(), title: "", details: "", date: null, @@ -74,8 +72,8 @@ export default function Lists () { return ( (index === tasks.length - 1) ? - - : + handleTaskDelete(t.id)} /> + : handleTaskDelete(t.id)} /> ) }) }