-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
mkbeefcake
committed
Dec 5, 2023
1 parent
95dabab
commit a021915
Showing
10 changed files
with
1,486 additions
and
27 deletions.
There are no files selected for viewing
413 changes: 413 additions & 0 deletions
413
distributor-node/src/services/networking/query-node/schema.graphql
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,270 @@ | ||
import { DatabaseManager, SubstrateEvent } from '@joystream/hydra-common' | ||
import { | ||
ICreateTag, | ||
IUpdateTag, | ||
IAssignTagToThread, | ||
IAssignTagToProposal, | ||
IUnassignTagFromThread, | ||
IUnassignTagFromProposal, | ||
IAllowTagToWorker, | ||
IDisallowTagToWorker, | ||
} from '@joystream/metadata-protobuf' | ||
import { DecodedMetadataObject } from '@joystream/metadata-protobuf/types' | ||
import { | ||
WorkingGroup, | ||
Tag, | ||
TagToWorker, | ||
TagToThread, | ||
TagToProposal, | ||
ForumThread, | ||
Proposal, | ||
} from 'query-node/dist/model' | ||
import { MetaprotocolTxError, getOneBy, getById, logger, getOneByOrFail, getByIdOrFail } from 'src/common' | ||
|
||
export async function processCreateTag( | ||
store: DatabaseManager, | ||
event: SubstrateEvent, | ||
metadata: DecodedMetadataObject<ICreateTag>, | ||
workgroup: WorkingGroup, | ||
isLead: boolean, | ||
workerId: number | ||
Check warning on line 30 in query-node/mappings/src/label/tag.ts GitHub Actions / Ubuntu Checks (18.x)
|
||
): Promise<any> { | ||
const { name, description, type, visibility } = metadata | ||
|
||
if (isLead === false) { | ||
return MetaprotocolTxError.TagPermNotAllowed | ||
} | ||
|
||
const tagId = `${event.blockNumber}-${event.indexInBlock}` | ||
Check warning on line 38 in query-node/mappings/src/label/tag.ts GitHub Actions / Ubuntu Checks (18.x)
|
||
|
||
const isTagExists = await getOneBy(store, Tag, { name: name }) | ||
|
||
if (isTagExists) { | ||
return MetaprotocolTxError.TagAlreadyExists | ||
} | ||
|
||
const newTag = new Tag({ | ||
name: name, | ||
description: description, | ||
type: type, | ||
visibility: visibility, | ||
}) | ||
|
||
await store.save<Tag>(newTag) | ||
logger.info('Tag has been created', { name }) | ||
|
||
return newTag | ||
} | ||
|
||
export async function processUpdateTag( | ||
store: DatabaseManager, | ||
event: SubstrateEvent, | ||
metadata: DecodedMetadataObject<IUpdateTag>, | ||
workingGroup: WorkingGroup, | ||
isLead: boolean, | ||
workerId: number | ||
Check warning on line 65 in query-node/mappings/src/label/tag.ts GitHub Actions / Ubuntu Checks (18.x)
|
||
): Promise<any> { | ||
const { tagId, name, description, type, visibility } = metadata | ||
|
||
if (isLead === false) { | ||
return MetaprotocolTxError.TagPermNotAllowed | ||
} | ||
|
||
const tag: Tag | undefined = await getById(store, Tag, tagId) | ||
|
||
if (!tag) { | ||
return MetaprotocolTxError.TagNotFound | ||
} | ||
|
||
if (name) { | ||
tag.name = name | ||
} | ||
|
||
if (description) { | ||
tag.description = description | ||
} | ||
|
||
if (type) { | ||
tag.type = type | ||
} | ||
|
||
if (visibility) { | ||
tag.visibility = visibility | ||
} | ||
|
||
await store.save<Tag>(tag) | ||
|
||
logger.info('Tag has been created', { name }) | ||
return tag | ||
} | ||
|
||
export async function processAssignTagToThread( | ||
store: DatabaseManager, | ||
event: SubstrateEvent, | ||
metadata: DecodedMetadataObject<IAssignTagToThread>, | ||
workingGroup: WorkingGroup, | ||
isLead: boolean, | ||
workerId: number | ||
): Promise<any> { | ||
const { tagId, threadId } = metadata | ||
|
||
if (!isLead) { | ||
await getOneByOrFail(store, TagToWorker, { tagId: tagId, workerId: workerId.toString() }) | ||
} | ||
|
||
await getByIdOrFail(store, ForumThread, threadId) | ||
const tagToThread: TagToThread | undefined = await getOneBy(store, TagToThread, { tagId: tagId, threadId: threadId }) | ||
|
||
if (!tagToThread) { | ||
const newTagToThread = new TagToThread({ | ||
tagId: tagId, | ||
threadId: threadId, | ||
}) | ||
await store.save<TagToThread>(newTagToThread) | ||
} | ||
|
||
logger.info('TagToThread has been assigned', { tagId, threadId }) | ||
return tagToThread | ||
} | ||
|
||
export async function processAssignTagToProposal( | ||
store: DatabaseManager, | ||
event: SubstrateEvent, | ||
metadata: DecodedMetadataObject<IAssignTagToProposal>, | ||
workingGroup: WorkingGroup, | ||
isLead: boolean, | ||
workerId: number | ||
): Promise<any> { | ||
const { tagId, proposalId } = metadata | ||
|
||
if (!isLead) { | ||
await getOneByOrFail(store, TagToWorker, { tagId: tagId, workerId: workerId.toString() }) | ||
} | ||
|
||
await getByIdOrFail(store, Proposal, proposalId) | ||
const tagToProposal: TagToProposal | undefined = await getOneBy(store, TagToProposal, { | ||
tagId: tagId, | ||
proposalId: proposalId, | ||
}) | ||
|
||
if (!tagToProposal) { | ||
const newTagToProposal = new TagToProposal({ | ||
tagId: tagId, | ||
proposalId: proposalId, | ||
}) | ||
await store.save<TagToProposal>(newTagToProposal) | ||
} | ||
|
||
logger.info('TagToProposal has been assigned', { tagId, proposalId }) | ||
return tagToProposal | ||
} | ||
|
||
export async function processUnassignTagFromThread( | ||
store: DatabaseManager, | ||
event: SubstrateEvent, | ||
metadata: DecodedMetadataObject<IUnassignTagFromThread>, | ||
workingGroup: WorkingGroup, | ||
isLead: boolean, | ||
workerId: number | ||
): Promise<any> { | ||
const { tagId, threadId } = metadata | ||
|
||
if (!isLead) { | ||
await getOneByOrFail(store, TagToWorker, { tagId: tagId, workerId: workerId.toString() }) | ||
} | ||
|
||
await getByIdOrFail(store, ForumThread, threadId) | ||
const tagToThread: TagToThread | undefined = await getOneBy(store, TagToThread, { tagId: tagId, threadId: threadId }) | ||
|
||
if (tagToThread) { | ||
await store.remove<TagToThread>(tagToThread) | ||
} | ||
|
||
logger.info('TagToThread has been unassigned', { tagId, threadId }) | ||
return tagToThread | ||
} | ||
|
||
export async function processUnassignTagFromProposal( | ||
store: DatabaseManager, | ||
event: SubstrateEvent, | ||
metadata: DecodedMetadataObject<IUnassignTagFromProposal>, | ||
workingGroup: WorkingGroup, | ||
isLead: boolean, | ||
workerId: number | ||
): Promise<any> { | ||
const { tagId, proposalId } = metadata | ||
|
||
if (!isLead) { | ||
await getOneByOrFail(store, TagToWorker, { tagId: tagId, workerId: workerId.toString() }) | ||
} | ||
|
||
await getByIdOrFail(store, Proposal, proposalId) | ||
|
||
const tagToProposal: TagToProposal | undefined = await getOneBy(store, TagToProposal, { | ||
tagId: tagId, | ||
proposalId: proposalId, | ||
}) | ||
|
||
if (tagToProposal) { | ||
await store.remove<TagToProposal>(tagToProposal) | ||
} | ||
|
||
logger.info('TagToProposal has been unassigned', { tagId, proposalId }) | ||
return tagToProposal | ||
} | ||
|
||
export async function processAllowTagToWorker( | ||
store: DatabaseManager, | ||
event: SubstrateEvent, | ||
metadata: DecodedMetadataObject<IAllowTagToWorker>, | ||
workingGroup: WorkingGroup, | ||
isLead: boolean, | ||
workerId: number | ||
Check warning on line 222 in query-node/mappings/src/label/tag.ts GitHub Actions / Ubuntu Checks (18.x)
|
||
): Promise<any> { | ||
const { tagId, workerId: assigneeId } = metadata | ||
|
||
if (!isLead) { | ||
return MetaprotocolTxError.TagPermNotAllowed | ||
} | ||
|
||
const tagToWorker: TagToWorker | undefined = await getOneBy(store, TagToWorker, { | ||
tagId: tagId, | ||
workerId: assigneeId, | ||
}) | ||
|
||
if (!tagToWorker) { | ||
const newTagToWorker = new TagToWorker({ | ||
tagId: tagId, | ||
workerId: assigneeId, | ||
}) | ||
await store.save<TagToWorker>(newTagToWorker) | ||
} | ||
|
||
logger.info('TagToWorker has been allowed', { tagId, assigneeId }) | ||
} | ||
|
||
export async function processDisallowTagToWorker( | ||
store: DatabaseManager, | ||
event: SubstrateEvent, | ||
metadata: DecodedMetadataObject<IDisallowTagToWorker>, | ||
workingGroup: WorkingGroup, | ||
isLead: boolean, | ||
workerId: number | ||
Check warning on line 252 in query-node/mappings/src/label/tag.ts GitHub Actions / Ubuntu Checks (18.x)
|
||
): Promise<any> { | ||
const { tagId, workerId: assigneeId } = metadata | ||
|
||
if (!isLead) { | ||
return MetaprotocolTxError.TagPermNotAllowed | ||
} | ||
|
||
const tagToWorker: TagToWorker | undefined = await getOneBy(store, TagToWorker, { | ||
tagId: tagId, | ||
workerId: assigneeId, | ||
}) | ||
|
||
if (tagToWorker) { | ||
await store.remove<TagToWorker>(tagToWorker) | ||
} | ||
|
||
logger.info('TagToWorker has been disallowed', { tagId, assigneeId }) | ||
} |
Oops, something went wrong.