accent answer not control en language
This commit is contained in:
parent
ccb5d42faa
commit
3a6488c5d1
|
@ -1,9 +1,6 @@
|
||||||
export type CheckPoint = {
|
import { Models } from 'appwrite'
|
||||||
$id: string
|
|
||||||
$collectionId: string
|
export interface CheckPoint extends Models.Document {
|
||||||
$createdAt: string
|
|
||||||
$databaseId: string
|
|
||||||
$permissions: string
|
|
||||||
$updatedAt: string
|
$updatedAt: string
|
||||||
CPAfter: string
|
CPAfter: string
|
||||||
CPAnswerID: string
|
CPAnswerID: string
|
||||||
|
@ -17,13 +14,7 @@ export type CheckPoint = {
|
||||||
CPType: 'CHECKBOX' | 'TEXT' | 'INFO' | 'RADIO' | 'NUMBER'
|
CPType: 'CHECKBOX' | 'TEXT' | 'INFO' | 'RADIO' | 'NUMBER'
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Experience = {
|
export interface Experience extends Models.Document {
|
||||||
$id: string
|
|
||||||
$collectionId: string
|
|
||||||
$createdAt: string
|
|
||||||
$databaseId: string
|
|
||||||
$permissions: string
|
|
||||||
$updatedAt: string
|
|
||||||
ExpApproved: boolean
|
ExpApproved: boolean
|
||||||
ExpCPsID: string[]
|
ExpCPsID: string[]
|
||||||
ExpCategory?: string
|
ExpCategory?: string
|
||||||
|
@ -41,3 +32,25 @@ export type Experience = {
|
||||||
checkPoints: Array<CheckPoint>
|
checkPoints: Array<CheckPoint>
|
||||||
rating: number
|
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<string>
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CPAnswerDocument extends Models.Document {
|
||||||
|
CPAnswer: string[]
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
export interface Account {
|
||||||
|
userId: string;
|
||||||
|
userName: string;
|
||||||
|
erantId: string;
|
||||||
|
userImage: string;
|
||||||
|
userInterests: string;
|
||||||
|
userRecommended: string;
|
||||||
|
userTravelBuddy: string;
|
||||||
|
termsAccepted: boolean;
|
||||||
|
}
|
|
@ -3,7 +3,7 @@ import { Account, Models, Permission, Query, Role } from 'appwrite'
|
||||||
import database from 'svelte-appwrite-client/src/lib/database'
|
import database from 'svelte-appwrite-client/src/lib/database'
|
||||||
import { getLocationDataFromLatAndLong } from '../locations'
|
import { getLocationDataFromLatAndLong } from '../locations'
|
||||||
import { Writable, writable } from 'svelte/store'
|
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'
|
import collections from '$lib/collections'
|
||||||
|
|
||||||
export type AnswerState = 'wrong-firstTime' | 'wrong-secondTime' | 'correct' | 'not-control' | null
|
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
|
//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) => {
|
export const load = async (pathName: string, previewQuestionsCount?: number, preview?: Function) => {
|
||||||
// @ts-ignore
|
const experience = (await databases.listDocuments<Models.Document & Experience>('63cef30d6da945dd4250', '63cef4bd210fdf2e5888', [Query.equal('ExpURL', pathName)])).documents[0]
|
||||||
const experience: Experience = (await databases.listDocuments('63cef30d6da945dd4250', '63cef4bd210fdf2e5888', [Query.equal('ExpURL', pathName)])).documents[0]
|
|
||||||
|
|
||||||
const rating = await getRating(experience.$id)
|
const rating = await getRating(experience.$id)
|
||||||
|
|
||||||
|
@ -32,12 +31,6 @@ export const load = async (pathName: string, previewQuestionsCount?: number, pre
|
||||||
.map((listItem) => listItem.documents)
|
.map((listItem) => listItem.documents)
|
||||||
.flat()
|
.flat()
|
||||||
|
|
||||||
/*if (checkPointsIds.indexOf(checkPointId) === previewQuestionsCount - 1) {
|
|
||||||
experience['rating'] = rating
|
|
||||||
experience['checkPoints'] = checkPoints
|
|
||||||
preview(experience)
|
|
||||||
}*/
|
|
||||||
|
|
||||||
experience['rating'] = rating
|
experience['rating'] = rating
|
||||||
experience['checkPoints'] = checkPointsDocument
|
experience['checkPoints'] = checkPointsDocument
|
||||||
|
|
||||||
|
@ -64,13 +57,15 @@ export const answer = async (experienceId: string, checkPointId: string, answer:
|
||||||
try {
|
try {
|
||||||
const checkPoint = await databases.getDocument('63cef30d6da945dd4250', '63cef84d908acf805758', checkPointId)
|
const checkPoint = await databases.getDocument('63cef30d6da945dd4250', '63cef84d908acf805758', checkPointId)
|
||||||
const { CPType, CPAnswerID } = checkPoint
|
const { CPType, CPAnswerID } = checkPoint
|
||||||
const correctAnswer = CPType !== 'INFO' ? (await databases.getDocument('63cef30d6da945dd4250', '63dd5c2b764061e40025', CPAnswerID)).CPAnswer : true
|
const correctAnswer =
|
||||||
|
CPType !== 'INFO' ? (await databases.getDocument<Models.Document & CPAnswerDocument>('63cef30d6da945dd4250', '63dd5c2b764061e40025', CPAnswerID)).CPAnswer : null
|
||||||
|
|
||||||
let correct: boolean = false
|
let correct: boolean = false
|
||||||
|
|
||||||
if (CPType === 'CHECKBOX') correct = JSON.stringify(answer) === JSON.stringify(correctAnswer)
|
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 === 'INFO') correct = false
|
||||||
|
if (CPType === 'TEXT') correct = correctAnswer[0].localeCompare(answer, 'en', { sensitivity: 'base' }) === 0
|
||||||
await saveAnswerIntoDatabase(experienceId, checkPointId, correct)
|
await saveAnswerIntoDatabase(experienceId, checkPointId, correct)
|
||||||
|
|
||||||
return correct
|
return correct
|
||||||
|
|
Loading…
Reference in New Issue