|
@@ -57,7 +57,6 @@ import {
|
|
userDefinedLicensePropertyNamesWithId,
|
|
userDefinedLicensePropertyNamesWithId,
|
|
videoMediaEncodingPropertyNamesWithId,
|
|
videoMediaEncodingPropertyNamesWithId,
|
|
videoPropertyNamesWithId,
|
|
videoPropertyNamesWithId,
|
|
- contentDirectoryClassNamesWithId,
|
|
|
|
ContentDirectoryKnownClasses,
|
|
ContentDirectoryKnownClasses,
|
|
featuredVideoPropertyNamesWithId,
|
|
featuredVideoPropertyNamesWithId,
|
|
} from '../content-dir-consts'
|
|
} from '../content-dir-consts'
|
|
@@ -80,7 +79,7 @@ import {
|
|
IMediaLocation,
|
|
IMediaLocation,
|
|
IFeaturedVideo,
|
|
IFeaturedVideo,
|
|
} from '../../types'
|
|
} from '../../types'
|
|
-import { getOrCreate } from '../get-or-create'
|
|
|
|
|
|
+import { getOrCreate, getKnownClass } from '../get-or-create'
|
|
|
|
|
|
const debug = Debug('mappings:content-directory')
|
|
const debug = Debug('mappings:content-directory')
|
|
|
|
|
|
@@ -91,22 +90,13 @@ async function contentDirectory_EntitySchemaSupportAdded(db: DB, event: Substrat
|
|
|
|
|
|
const { blockNumber: block } = event
|
|
const { blockNumber: block } = event
|
|
const entityId = decode.stringIfyEntityId(event)
|
|
const entityId = decode.stringIfyEntityId(event)
|
|
- const classEntity = await db.get(ClassEntity, { where: { id: entityId } })
|
|
|
|
|
|
|
|
- if (classEntity === undefined) {
|
|
|
|
- console.log(`Class not found for the EntityId: ${entityId}`)
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- const cls = contentDirectoryClassNamesWithId.find((c) => c.classId === classEntity.classId)
|
|
|
|
- if (cls === undefined) {
|
|
|
|
- console.log('Not recognized class')
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
|
|
+ const knownClass = await getKnownClass(db, { where: { id: entityId } })
|
|
|
|
+ if (!knownClass) return
|
|
|
|
|
|
const arg: IDBBlockId = { db, block, id: entityId }
|
|
const arg: IDBBlockId = { db, block, id: entityId }
|
|
|
|
|
|
- switch (cls.name) {
|
|
|
|
|
|
+ switch (knownClass.name) {
|
|
case ContentDirectoryKnownClasses.CHANNEL:
|
|
case ContentDirectoryKnownClasses.CHANNEL:
|
|
await createChannel(
|
|
await createChannel(
|
|
arg,
|
|
arg,
|
|
@@ -183,7 +173,7 @@ async function contentDirectory_EntitySchemaSupportAdded(db: DB, event: Substrat
|
|
break
|
|
break
|
|
|
|
|
|
default:
|
|
default:
|
|
- throw new Error(`Unknown class name: ${cls.name}`)
|
|
|
|
|
|
+ throw new Error(`Unknown class name: ${knownClass.name}`)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -194,19 +184,10 @@ async function contentDirectory_EntityRemoved(db: DB, event: SubstrateEvent): Pr
|
|
const entityId = decode.stringIfyEntityId(event)
|
|
const entityId = decode.stringIfyEntityId(event)
|
|
const where: IWhereCond = { where: { id: entityId } }
|
|
const where: IWhereCond = { where: { id: entityId } }
|
|
|
|
|
|
- const classEntity = await db.get(ClassEntity, where)
|
|
|
|
- if (classEntity === undefined) {
|
|
|
|
- console.log(`Class not found for the EntityId: ${entityId}`)
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- const cls = contentDirectoryClassNamesWithId.find((c) => c.classId === classEntity.classId)
|
|
|
|
- if (cls === undefined) {
|
|
|
|
- console.log('Unknown class')
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
|
|
+ const knownClass = await getKnownClass(db, where)
|
|
|
|
+ if (!knownClass) return
|
|
|
|
|
|
- switch (cls.name) {
|
|
|
|
|
|
+ switch (knownClass.name) {
|
|
case ContentDirectoryKnownClasses.CHANNEL:
|
|
case ContentDirectoryKnownClasses.CHANNEL:
|
|
await removeChannel(db, where)
|
|
await removeChannel(db, where)
|
|
break
|
|
break
|
|
@@ -259,8 +240,10 @@ async function contentDirectory_EntityRemoved(db: DB, event: SubstrateEvent): Pr
|
|
break
|
|
break
|
|
|
|
|
|
default:
|
|
default:
|
|
- throw new Error(`Unknown class name: ${cls.name}`)
|
|
|
|
|
|
+ throw new Error(`Unknown class name: ${knownClass.name}`)
|
|
}
|
|
}
|
|
|
|
+ const ce = await db.get(ClassEntity, where)
|
|
|
|
+ if (ce) await db.remove<ClassEntity>(ce)
|
|
}
|
|
}
|
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
@@ -290,21 +273,17 @@ async function contentDirectory_EntityPropertyValuesUpdated(db: DB, event: Subst
|
|
|
|
|
|
const { 2: newPropertyValues } = extrinsic.args
|
|
const { 2: newPropertyValues } = extrinsic.args
|
|
const entityId = decode.stringIfyEntityId(event)
|
|
const entityId = decode.stringIfyEntityId(event)
|
|
-
|
|
|
|
- const ce = await db.get(ClassEntity, { where: { id: entityId } })
|
|
|
|
- if (ce === undefined) throw Error(`Class not found for the entity id: ${entityId}`)
|
|
|
|
-
|
|
|
|
- const cls = contentDirectoryClassNamesWithId.find((c) => c.classId === ce.classId)
|
|
|
|
- if (cls === undefined) throw Error(`Not known class id: ${ce.classId}`)
|
|
|
|
-
|
|
|
|
const where: IWhereCond = { where: { id: entityId } }
|
|
const where: IWhereCond = { where: { id: entityId } }
|
|
|
|
|
|
|
|
+ const knownClass = await getKnownClass(db, where)
|
|
|
|
+ if (!knownClass) return
|
|
|
|
+
|
|
// TODO: change setProperties method signature to accecpt SubstrateExtrinsic, then remove the following
|
|
// TODO: change setProperties method signature to accecpt SubstrateExtrinsic, then remove the following
|
|
// line. The reason we push the same arg is beacuse of the setProperties method check the 3rd indices
|
|
// line. The reason we push the same arg is beacuse of the setProperties method check the 3rd indices
|
|
// to get properties values
|
|
// to get properties values
|
|
extrinsic.args.push(newPropertyValues)
|
|
extrinsic.args.push(newPropertyValues)
|
|
|
|
|
|
- switch (cls.name) {
|
|
|
|
|
|
+ switch (knownClass.name) {
|
|
case ContentDirectoryKnownClasses.CHANNEL:
|
|
case ContentDirectoryKnownClasses.CHANNEL:
|
|
updateChannelEntityPropertyValues(db, where, decode.setProperties<IChannel>(event, channelPropertyNamesWithId), 0)
|
|
updateChannelEntityPropertyValues(db, where, decode.setProperties<IChannel>(event, channelPropertyNamesWithId), 0)
|
|
break
|
|
break
|
|
@@ -406,7 +385,7 @@ async function contentDirectory_EntityPropertyValuesUpdated(db: DB, event: Subst
|
|
break
|
|
break
|
|
|
|
|
|
default:
|
|
default:
|
|
- throw new Error(`Unknown class name: ${cls.name}`)
|
|
|
|
|
|
+ throw new Error(`Unknown class name: ${knownClass.name}`)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|