komoot planned vs completed
This commit is contained in:
@@ -36,7 +36,10 @@ func SyncKomoot(app *pocketbase.PocketBase) error {
|
||||
|
||||
userId := i.GetString("user")
|
||||
komootString := i.GetString("komoot")
|
||||
var komootIntegration KomootIntegration
|
||||
komootIntegration := KomootIntegration{
|
||||
Planned: true,
|
||||
Completed: true,
|
||||
}
|
||||
json.Unmarshal([]byte(komootString), &komootIntegration)
|
||||
|
||||
if !komootIntegration.Active || komootIntegration.Email == "" || komootIntegration.Password == "" {
|
||||
@@ -67,7 +70,7 @@ func SyncKomoot(app *pocketbase.PocketBase) error {
|
||||
break
|
||||
}
|
||||
|
||||
hasNewTours, err = syncTrailWithTours(app, k, userId, tours)
|
||||
hasNewTours, err = syncTrailWithTours(app, k, komootIntegration, userId, tours)
|
||||
if err != nil {
|
||||
warning := fmt.Sprintf("error syncing komoot tours with trails: %v\n", err)
|
||||
fmt.Print(warning)
|
||||
@@ -172,14 +175,14 @@ func (k *KomootApi) fetchDetailedTour(tour KomootTour) (*DetailedKomootTour, err
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func syncTrailWithTours(app *pocketbase.PocketBase, k *KomootApi, user string, tours []KomootTour) (bool, error) {
|
||||
func syncTrailWithTours(app *pocketbase.PocketBase, k *KomootApi, i KomootIntegration, user string, tours []KomootTour) (bool, error) {
|
||||
hasNewTours := false
|
||||
for _, tour := range tours {
|
||||
trails, err := app.Dao().FindRecordsByFilter("trails", "external_id = {:id}", "", 1, 0, dbx.Params{"id": strconv.Itoa(int(tour.ID))})
|
||||
if err != nil {
|
||||
return hasNewTours, err
|
||||
}
|
||||
if len(trails) != 0 {
|
||||
if len(trails) != 0 || (tour.Type == "tour_planned" && !i.Planned) || (tour.Type == "tour_recorded" && !i.Completed) {
|
||||
continue
|
||||
}
|
||||
hasNewTours = true
|
||||
|
||||
@@ -6,6 +6,8 @@ type KomootIntegration struct {
|
||||
Active bool `json:"active"`
|
||||
Email string `json:"email"`
|
||||
Password string `json:"password"`
|
||||
Planned bool `json:"planned"`
|
||||
Completed bool `json:"completed"`
|
||||
}
|
||||
|
||||
type LoginResponse struct {
|
||||
|
||||
@@ -735,7 +735,10 @@ func bootstrapMeilisearchTrails(app *pocketbase.PocketBase, client meilisearch.S
|
||||
return err
|
||||
}
|
||||
|
||||
client.Index("trails").DeleteAllDocuments()
|
||||
_, err := client.Index("trails").DeleteAllDocuments()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, trail := range trails {
|
||||
author, err := app.Dao().FindRecordById("users", trail.GetString(("author")))
|
||||
if err != nil {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<script lang="ts">
|
||||
import Modal from "$lib/components/base/modal.svelte";
|
||||
import TextField from "$lib/components/base/text_field.svelte";
|
||||
import Toggle from "$lib/components/base/toggle.svelte";
|
||||
import { KomootSchema } from "$lib/models/api/integration_schema";
|
||||
import type {
|
||||
Integration,
|
||||
@@ -20,7 +21,7 @@
|
||||
let modal: Modal;
|
||||
|
||||
export function openModal() {
|
||||
errors.set({})
|
||||
errors.set({});
|
||||
modal.openModal();
|
||||
}
|
||||
|
||||
@@ -32,13 +33,15 @@
|
||||
initialValues: {
|
||||
email: integration?.komoot?.email ?? "",
|
||||
password: integration?.komoot?.password ?? "",
|
||||
completed: integration?.komoot?.completed ?? true,
|
||||
planned: integration?.komoot?.planned ?? true,
|
||||
active: integration?.komoot?.active ?? false,
|
||||
},
|
||||
extend: validator({
|
||||
schema: KomootSchema,
|
||||
}),
|
||||
onSubmit: async (form) => {
|
||||
form.active = integration?.komoot?.active ?? form.active
|
||||
form.active = integration?.komoot?.active ?? form.active;
|
||||
onsave?.(form);
|
||||
modal.closeModal();
|
||||
},
|
||||
@@ -66,6 +69,14 @@
|
||||
type="password"
|
||||
error={$errors.password}
|
||||
></TextField>
|
||||
<div class="flex gap-x-4">
|
||||
<Toggle name="planned" label={$_("completed-tours", { values: { n: 2 } })}
|
||||
></Toggle>
|
||||
<Toggle
|
||||
name="completed"
|
||||
label={$_("planned-tours", { values: { n: 2 } })}
|
||||
></Toggle>
|
||||
</div>
|
||||
</form>
|
||||
{/snippet}
|
||||
{#snippet footer()}
|
||||
|
||||
Reference in New Issue
Block a user