diff --git a/src/lib/TStypes/experiences.ts b/src/lib/TStypes/experiences.ts index a740e9e..d202658 100644 --- a/src/lib/TStypes/experiences.ts +++ b/src/lib/TStypes/experiences.ts @@ -1,9 +1,6 @@ -export type CheckPoint = { - $id: string - $collectionId: string - $createdAt: string - $databaseId: string - $permissions: string +import { Models } from 'appwrite' + +export interface CheckPoint extends Models.Document { $updatedAt: string CPAfter: string CPAnswerID: string @@ -17,13 +14,7 @@ export type CheckPoint = { CPType: 'CHECKBOX' | 'TEXT' | 'INFO' | 'RADIO' | 'NUMBER' } -export type Experience = { - $id: string - $collectionId: string - $createdAt: string - $databaseId: string - $permissions: string - $updatedAt: string +export interface Experience extends Models.Document { ExpApproved: boolean ExpCPsID: string[] ExpCategory?: string @@ -41,3 +32,25 @@ export type Experience = { checkPoints: Array rating: number } + +export interface ExperienceDocument extends Models.Document { + ExpApproved: boolean + ExpCPsID: string[] + ExpCategory?: string + ExpEnd0: string + ExpEnd60: string + ExpEnd100: string + ExpImage?: string + ExpIntroduction: string + ExpLocation: number[] + ExpName: string + ExpStart: string + ExpTestingCode: string + ExpURL: string + UserID: string + checkPoints: Array +} + +export interface CPAnswerDocument extends Models.Document { + CPAnswer: string[] +} diff --git a/src/lib/TStypes/users.ts b/src/lib/TStypes/users.ts new file mode 100644 index 0000000..a264516 --- /dev/null +++ b/src/lib/TStypes/users.ts @@ -0,0 +1,10 @@ +export interface Account { + userId: string; + userName: string; + erantId: string; + userImage: string; + userInterests: string; + userRecommended: string; + userTravelBuddy: string; + termsAccepted: boolean; +} diff --git a/src/lib/utils/database/experience.ts b/src/lib/utils/database/experience.ts index a976ff7..1d9ad91 100644 --- a/src/lib/utils/database/experience.ts +++ b/src/lib/utils/database/experience.ts @@ -3,7 +3,7 @@ import { Account, Models, Permission, Query, Role } from 'appwrite' import database from 'svelte-appwrite-client/src/lib/database' import { getLocationDataFromLatAndLong } from '../locations' import { Writable, writable } from 'svelte/store' -import { CheckPoint, Experience } from '$lib/TStypes/experiences' +import { CPAnswerDocument, CheckPoint, Experience } from '$lib/TStypes/experiences' import collections from '$lib/collections' export type AnswerState = 'wrong-firstTime' | 'wrong-secondTime' | 'correct' | 'not-control' | null @@ -13,8 +13,7 @@ userStore.subscribe((res) => (user = res)) //Loading of checkpoints and rating is done in the same function to prevent multiple requests to the database export const load = async (pathName: string, previewQuestionsCount?: number, preview?: Function) => { - // @ts-ignore - const experience: Experience = (await databases.listDocuments('63cef30d6da945dd4250', '63cef4bd210fdf2e5888', [Query.equal('ExpURL', pathName)])).documents[0] + const experience = (await databases.listDocuments('63cef30d6da945dd4250', '63cef4bd210fdf2e5888', [Query.equal('ExpURL', pathName)])).documents[0] const rating = await getRating(experience.$id) @@ -32,12 +31,6 @@ export const load = async (pathName: string, previewQuestionsCount?: number, pre .map((listItem) => listItem.documents) .flat() - /*if (checkPointsIds.indexOf(checkPointId) === previewQuestionsCount - 1) { - experience['rating'] = rating - experience['checkPoints'] = checkPoints - preview(experience) - }*/ - experience['rating'] = rating experience['checkPoints'] = checkPointsDocument @@ -64,13 +57,15 @@ export const answer = async (experienceId: string, checkPointId: string, answer: try { const checkPoint = await databases.getDocument('63cef30d6da945dd4250', '63cef84d908acf805758', checkPointId) const { CPType, CPAnswerID } = checkPoint - const correctAnswer = CPType !== 'INFO' ? (await databases.getDocument('63cef30d6da945dd4250', '63dd5c2b764061e40025', CPAnswerID)).CPAnswer : true + const correctAnswer = + CPType !== 'INFO' ? (await databases.getDocument('63cef30d6da945dd4250', '63dd5c2b764061e40025', CPAnswerID)).CPAnswer : null let correct: boolean = false if (CPType === 'CHECKBOX') correct = JSON.stringify(answer) === JSON.stringify(correctAnswer) - if (CPType === 'RADIO' || CPType === 'NUMBER' || CPType === 'TEXT') correct = answer === correctAnswer[0] + if (CPType === 'RADIO' || CPType === 'NUMBER') correct = answer === correctAnswer[0] if (CPType === 'INFO') correct = false + if (CPType === 'TEXT') correct = correctAnswer[0].localeCompare(answer, 'en', { sensitivity: 'base' }) === 0 await saveAnswerIntoDatabase(experienceId, checkPointId, correct) return correct