From 1d68a0c7d293a822ece7840be027af5c3a012100 Mon Sep 17 00:00:00 2001 From: Emil Date: Mon, 18 Dec 2023 09:07:49 +0100 Subject: [PATCH] Changed away from any. Minor fixes from PR. --- .../integrationsTests/groupHandler.test.tsx | 16 +++++------ app/(tabs)/shoppingList/index.tsx | 2 +- constants/Database.ts | 2 +- handlers/group.ts | 6 ++--- handlers/list.ts | 4 +-- handlers/meal.ts | 2 +- package-lock.json | 27 ++++++++++++++++++- 7 files changed, 42 insertions(+), 17 deletions(-) diff --git a/__tests__/integrationsTests/groupHandler.test.tsx b/__tests__/integrationsTests/groupHandler.test.tsx index d750586..a6f052c 100644 --- a/__tests__/integrationsTests/groupHandler.test.tsx +++ b/__tests__/integrationsTests/groupHandler.test.tsx @@ -118,7 +118,7 @@ describe('GroupHandler', () => { function callbackTest() : boolean{ function checkIfUserInGroup(){ - GunDB.gun.user(userPub).get("groupId").once((id: any) => { + GunDB.gun.user(userPub).get("groupId").once((id: string) => { expect(id).toBeDefined() //The logged in user should now have a groupId testData.groupId = id checkIfGroupExists(GunDB.gun.get("groups").get("groupId").get(id)) @@ -129,13 +129,13 @@ describe('GroupHandler', () => { checkIfGroupHasMember(context) } function checkIfGroupHasMember(context : any){ - context.get("members").map().once((memberId : any) => { + context.get("members").map().once((memberId : string) => { expect(memberId).toBe(userPub) //The group should have the current user listed as a member checkIfGroupHasName(context) }) } function checkIfGroupHasName(context : any){ - context.get("name").once((name : any) => { + context.get("name").once((name : string) => { expect(name).toBe(expectedGroupName) //The group should have the given name testData.groupName = expectedGroupName done() @@ -160,7 +160,7 @@ describe('GroupHandler', () => { function test(){ function callbackTest(bool : boolean) : void{ function checkIfUserInGroup(){ - GunDB.gun.user(userPub).get("groupId").once((id: any) => { + GunDB.gun.user(userPub).get("groupId").once((id: string) => { expect(id).toBeDefined() //The logged in user should now have a groupId expect(id).toBe(groupIdToJoin) //The id should be the same as the group we wanted to join checkIfGroupHasMember(GunDB.gun.get("groups").get("groupId").get(id)) @@ -194,14 +194,14 @@ describe('GroupHandler', () => { function test(){ function callbackTest(bool : boolean) : void{ function checkIfUserInGroup(){ - GunDB.gun.user(userPub).get("groupId").once((id: any) => { + GunDB.gun.user(userPub).get("groupId").once((id: string) => { expect(id).toBeUndefined() //The logged in user should now have a groupId checkIfGroupExistsInGun() }) } function checkIfGroupExistsInGun(){ const context = GunDB.gun.get("groups").get("groupId").get(groupIdToJoin) - context.once((data : any) => { + context.once((data : string) => { expect(data).toBeUndefined() //The group id should still not exist done() }) @@ -314,7 +314,7 @@ describe('GroupHandler', () => { function callbackTest() : boolean{ function checkIfUserInGroup(){ - GunDB.gun.user(userPub).get("groupId").once((id: any) => { + GunDB.gun.user(userPub).get("groupId").once((id: string) => { expect(id).toBeDefined() //The logged in user should now have a groupId checkIfGroupExists(GunDB.gun.get("groups").get("groupId").get(id)) }) @@ -350,7 +350,7 @@ describe('GroupHandler', () => { } function checkIfGroupHasName(context : any){ - context.get("name").once((name : any) => { + context.get("name").once((name : string) => { expect(name).toBe(expectedGroupName) //The group should have the given name GunDB.gun.get("groups").get("groupId").get(testData.groupId).get("name").once((oldName : any) => { expect(oldName).toBe(expectedGroupName) diff --git a/app/(tabs)/shoppingList/index.tsx b/app/(tabs)/shoppingList/index.tsx index 8361709..44e21cf 100644 --- a/app/(tabs)/shoppingList/index.tsx +++ b/app/(tabs)/shoppingList/index.tsx @@ -76,7 +76,7 @@ export default function ToBeBoughtScreen() { } ) - gun.user(userPub).get('fullName').open((data: any) => { + gun.user(userPub).get('fullName').once((data: string) => { setUsername(data); }); diff --git a/constants/Database.ts b/constants/Database.ts index 8bdb78e..7f83bf6 100644 --- a/constants/Database.ts +++ b/constants/Database.ts @@ -16,7 +16,7 @@ AsyncStorage.clear() //rad asyncstorage adapter, on Android asyncstorage has 6mb limit by default const asyncStore = asyncsStore({AsyncStorage}); let gun = Gun({ -peers: ['http://130.225.39.205:8080/gun'], +// peers: ['http://130.225.39.205:8080/gun'], store: asyncStore, radisk: true, localStorage: false, diff --git a/handlers/group.ts b/handlers/group.ts index c2fa762..3332f68 100644 --- a/handlers/group.ts +++ b/handlers/group.ts @@ -1,6 +1,6 @@ - import { Expense } from '../helpers/calculateExpenses'; import { v4 as uuid } from 'uuid' + interface IGroup { create(groupName: string, callback : () => void): void; join(uuid: string, callback : (ack: Boolean) => void): void; @@ -24,7 +24,7 @@ class GroupHandle implements IGroup { context.get("members").set(userPub) context.get("name").put(groupName) user.get("groupId").put(groupId) - user.get('fullName').once((data: any) => { + user.get('fullName').once((data: string) => { if (data != undefined){ this.gun.get('groups').get("groupId").get(groupId).get('expenses').set(new Expense(data, 0, JSON.stringify([data]))); } @@ -41,7 +41,7 @@ class GroupHandle implements IGroup { let user = this.gun.user(userPub) context.get("members").set(userPub) user.get("groupId").put(uuid) - user.get('fullName').once((data: any) => { + user.get('fullName').once((data: string) => { if (data != undefined){ this.gun.get('groups').get("groupId").get(uuid).get('expenses').set(new Expense(data, 0, JSON.stringify([data]))); } diff --git a/handlers/list.ts b/handlers/list.ts index 2e77d3c..7f78c6f 100644 --- a/handlers/list.ts +++ b/handlers/list.ts @@ -20,10 +20,10 @@ class ShoppingListHandler implements IShoppingList { constructor(gun: Gun) { this.gun = gun; - gun.user(userPub).get("groupId").on((id : any) => { + gun.user(userPub).get("groupId").on((id : string) => { this.groupId = id }) - gun.user(userPub).get("fullName").on((data: any) => { + gun.user(userPub).get("fullName").on((data: string) => { this.userName = data }) } diff --git a/handlers/meal.ts b/handlers/meal.ts index 3e842cc..6ecb9e0 100644 --- a/handlers/meal.ts +++ b/handlers/meal.ts @@ -9,7 +9,7 @@ class MealPlanHandle implements IMealPlan { constructor(private gun: Gun) { this.user = this.gun.user(userPub); - this.user.get("groupId").once((data: any) => { + this.user.get("groupId").once((data: string) => { this.groupId = data }); } diff --git a/package-lock.json b/package-lock.json index 91c391f..2e3f9f9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10248,6 +10248,32 @@ "node": ">=8" } }, + "node_modules/dom-serializer": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-2.0.0.tgz", + "integrity": "sha512-wIkAryiqt/nV5EQKqQpo3SToSOV9J0DnbJqwK7Wv/Trc92zIAYZ4FlMu+JPFW1DfGFt81ZTCGgDEabffXeLyJg==", + "peer": true, + "dependencies": { + "domelementtype": "^2.3.0", + "domhandler": "^5.0.2", + "entities": "^4.2.0" + }, + "funding": { + "url": "https://github.com/cheeriojs/dom-serializer?sponsor=1" + } + }, + "node_modules/domelementtype": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-2.3.0.tgz", + "integrity": "sha512-OLETBj6w0OsagBwdXnPdN0cnMfF9opN69co+7ZrbfPGrdpPVNBUj02spi6B1N7wChLQiPn4CSH/zJvXw56gmHw==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/fb55" + } + ], + "peer": true + }, "node_modules/domexception": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/domexception/-/domexception-4.0.0.tgz", @@ -10358,7 +10384,6 @@ "version": "4.5.0", "resolved": "https://registry.npmjs.org/entities/-/entities-4.5.0.tgz", "integrity": "sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw==", - "dev": true, "engines": { "node": ">=0.12" },