mirror of
https://gitea.tendokyu.moe/ppc/amnet.git
synced 2026-09-22 22:28:22 +03:00
fix schema linkage
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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,4 +1,4 @@
|
||||
import {AMPhysicalCardData} from "./AMCard";
|
||||
import {AMPhysicalCardData} from "./AMPhysicalCardData";
|
||||
|
||||
export interface AMCardData {
|
||||
code: string;
|
||||
|
||||
@@ -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}
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user