Untitled

 avatar
user_6688396
plain_text
a year ago
1.8 kB
3
Indexable
Never
async bindFormWorkItem(
    conn: SQLServer,
    controlTransaction: boolean,
    formId: number,
    workItemId: number,
    formClassificationId: number,
    recordUserId: number
  ) {
    try {
      if (controlTransaction) {
        await conn.beginTransaction();
      }

      const previousJsonDescription = await this.selectOne(
        conn,
        {
          workItemId,
          formId,
        }
      );

      const data: any = {
        formId: formId,
        workItemId: workItemId,
        formClassificationId: formClassificationId,
        recordUserId: recordUserId,
        creationUserId: recordUserId
      };

      const newJsonDescription = await this.maintain(
        conn,
        data,
        rtFullRecord
      );

      /*------------------------------------------LOGS-----------------------------------------*/
      const logs: any = {
        formId: formId,
        creationUserId: recordUserId,
        previousJsonDescription: null,
        newJsonDescription
      };

      if (!previousJsonDescription && newJsonDescription) {
        logs.logTypeId = FormLogType.ChangeFormClassificationWorkItem;
      } else if (
        (previousJsonDescription && newJsonDescription) &&
        (JSON.stringify(previousJsonDescription) !== JSON.stringify(newJsonDescription))
      ) {
        logs.logTypeId = FormLogType.CreateFormWorkItem;
      }

      if (logs.logTypeId) {
        await new ROceFormsLogs().insert(
          conn,
          logs,
          rtNone
        );
      }

      if (controlTransaction) {
        await conn.commitTransaction();
      }

      return newJsonDescription;
    } catch (e) {
      if (controlTransaction) {
        await conn.rollbackTransaction();
      }

      throw e;
    }
  }