public async updateDraft()

in source/packages/services/assetlibrary/src/types/types.full.dao.ts [370:477]


    public async updateDraft(existing: TypeModel, updated: TypeModel): Promise<void> {
        logger.debug(
            `types.full.dao updateDraft: in: existing: ${JSON.stringify(
                existing
            )}, updated: ${JSON.stringify(updated)}`
        );

        const id = `type___${existing.templateId}`;

        const conn = await super.getConnection();
        const traverser = conn.traversal
            .V(id)
            .outE('current_definition')
            .has('status', 'draft')
            .inV()
            .as('definition')
            .property(
                process.cardinality.single,
                'definition',
                JSON.stringify(updated.schema.definition)
            )
            .property(process.cardinality.single, 'lastUpdated', new Date().toISOString());

        if (updated.schema.relations) {
            const changedRelations = this.identifyChangedRelations(
                existing.schema.relations,
                updated.schema.relations
            );
            logger.debug(
                `types.full.dao updateDraft: changedRelations: ${JSON.stringify(
                    changedRelations
                )}`
            );

            const removedRelations: process.GraphTraversal[] = [];

            Object.keys(changedRelations.remove.in).forEach((key) => {
                changedRelations.remove.in[key].forEach((value) => {
                    removedRelations.push(
                        __.select('definition')
                            .inE('relationship')
                            .has('name', key)
                            .has('fromTemplate', value)
                    );
                });
            });

            Object.keys(changedRelations.remove.out).forEach((key) => {
                changedRelations.remove.out[key].forEach((value) => {
                    removedRelations.push(
                        __.select('definition')
                            .outE('relationship')
                            .has('name', key)
                            .has('toTemplate', value)
                    );
                });
            });

            if (removedRelations.length > 0) {
                traverser
                    .select('definition')
                    .local(__.union(...removedRelations))
                    .drop();
            }

            Object.keys(changedRelations.add.in).forEach((relation) => {
                changedRelations.add.in[relation].forEach((t) => {
                    const templateName = isRelationTargetExpanded(t) ? t.name : t;
                    const includeInAuth = isRelationTargetExpanded(t)
                        ? t.includeInAuth
                        : undefined;
                    this.addCreateInboundRelationStepToTraversal(
                        existing.templateId,
                        templateName,
                        relation,
                        includeInAuth,
                        traverser
                    );
                });
            });

            Object.keys(changedRelations.add.out).forEach((relation) => {
                changedRelations.add.out[relation].forEach((t) => {
                    const templateName = isRelationTargetExpanded(t) ? t.name : t;
                    const includeInAuth = isRelationTargetExpanded(t)
                        ? t.includeInAuth
                        : undefined;
                    this.addCreateOutboundRelationStepToTraversal(
                        existing.templateId,
                        templateName,
                        relation,
                        includeInAuth,
                        traverser
                    );
                });
            });
        }

        logger.silly(`types.full.dao updateDraft: traverser: ${JSON.stringify(traverser)}`);
        const result = await traverser.next();
        logger.silly(`types.full.dao updateDraft: result: ${JSON.stringify(result)}`);

        if (result === undefined || result.value === null) {
            logger.debug(`types.full.dao updateDraft: exit: result: undefined`);
            return undefined;
        }
        logger.debug(`types.full.dao updateDraft: exit:`);
    }