fix schema linkage

This commit is contained in:
ppc
2025-04-02 19:27:24 +01:00
parent 4e69f9a4b1
commit 40fbf475f4
5 changed files with 41 additions and 33 deletions
+3 -2
View File
@@ -3,10 +3,11 @@ import {Card, Paragraph, useTheme} from "react-native-paper";
import {useCallback, useLayoutEffect, useState} from "react";
import {TextInput, TouchableOpacity, View} from "react-native";
import RealmContext from "../../models/RealmContext";
import {useModalStyles} from "../../utils/ModalStyles";
import RealmContext from "../../models/RealmContext";
import {AMCard, AMPhysicalCardData} from "../../models/AMCard";
import {AMCard} from "../../models/AMCard";
import {AMPhysicalCardData} from "../../models/AMPhysicalCardData";
import {felicaCardReadAsync, icCard0008Number, ICType} from "../../lib/iccard";
const {useRealm} = RealmContext;
+7 -29
View File
@@ -1,7 +1,10 @@
import {Realm} from "realm";
import {AmusementICVendor, ICType} from "../lib/iccard";
import {AMCardRecentUse} from "./AMCardRecentUse";
import {ICType} from "../lib/iccard";
import {AMCardData} from "./AMCardData";
import {AMCardRecentUse} from "./AMCardRecentUse";
import {AMPhysicalCardData} from "./AMPhysicalCardData";
export class AMCard extends Realm.Object<AMCard> implements AMCardData {
_id!: Realm.BSON.ObjectId;
@@ -51,34 +54,9 @@ export class AMCard extends Realm.Object<AMCard> implements AMCardData {
name: {type: "string", default: "New Card", indexed: true},
added: {type: "date", default: new Date(), indexed: true},
lastUsed: {type: "date", optional: true, indexed: true},
usageHistory: {type: "linkingObjects", objectType: "cardUsageHistory", property: "card"},
physicalCardData: {type: "object", objectType: "physicalCard", optional: true}
recentUses: {type: "linkingObjects", objectType: AMCardRecentUse.schema.name, property: "card"},
physicalCardData: {type: "object", objectType: AMPhysicalCardData.schema.name, optional: true}
}
};
}
/**
* Holds physical card information when a card is imported via NFC/FeliCa
*/
export class AMPhysicalCardData extends Realm.Object<AMPhysicalCardData> {
cardIDm: string;
cardType: ICType;
cardVendor: AmusementICVendor | null;
get isBootlegAmusementCard() {
// real cards have an IDm manufacturer code of 012E (first two bytes of the IDm or in this case, the first 4 characters)
return this.cardType === ICType.Amusement && !this.cardIDm.startsWith("012E");
}
static schema: Realm.ObjectSchema = {
name: "physicalCard",
primaryKey: "cardIDm",
properties: {
cardIDm: "string",
cardType: "int",
cardVendor: {type: "int", optional: true}
}
};
}
+1 -1
View File
@@ -1,4 +1,4 @@
import {AMPhysicalCardData} from "./AMCard";
import {AMPhysicalCardData} from "./AMPhysicalCardData";
export interface AMCardData {
code: string;
+28
View File
@@ -0,0 +1,28 @@
import {Realm} from "realm";
import {AmusementICVendor, ICType} from "../lib/iccard";
/**
* Holds physical card information when a card is imported via NFC/FeliCa
*/
export class AMPhysicalCardData extends Realm.Object<AMPhysicalCardData> {
cardIDm: string;
cardType: ICType;
cardVendor: AmusementICVendor | null;
get isBootlegAmusementCard() {
// real cards have an IDm manufacturer code of 012E (first two bytes of the IDm or in this case, the first 4 characters)
return this.cardType === ICType.Amusement && !this.cardIDm.startsWith("012E");
}
static schema: Realm.ObjectSchema = {
name: "physicalCard",
primaryKey: "cardIDm",
properties: {
cardIDm: "string",
cardType: "int",
cardVendor: {type: "int", optional: true}
}
};
}
+2 -1
View File
@@ -1,9 +1,10 @@
import {Realm} from "realm";
import {createRealmContext} from "@realm/react";
import {AMCard} from "./AMCard";
import {AMServer} from "./AMServer";
import {AMCardRecentUse} from "./AMCardRecentUse";
import {AMCard, AMPhysicalCardData} from "./AMCard";
import {AMPhysicalCardData} from "./AMPhysicalCardData";
const migrationFunction = (oldRealm: Realm, newRealm: Realm) => {
if (oldRealm.schemaVersion < 5) {