{"size": 874, "ext": "js", "max_stars_repo_path": "functions/maintanances/updateStatus.js", "max_stars_repo_name": "sdymj84/apt", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "functions/maintanances/updateStatus.js", "max_issues_repo_name": "sdymj84/apt", "max_issues_repo_issues_event_min_datetime": "2020-09-04T16:30:14.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-12T07:06:15.000Z", "max_forks_repo_path": "functions/maintanances/updateStatus.js", "max_forks_repo_name": "sdymj84/apt-api", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 6, "max_forks_count": null, "avg_line_length": 24.2777777778, "max_line_length": 76, "alphanum_fraction": 0.6556064073}
/* Use Case  
1. Manager update status from OPEN to IN PROGRESS / IN PROGRESS to COMPLETED

*/


import * as dynamoDbLib from "../../libs/dynamodb-lib";
import { success, failure } from "../../libs/response-lib";

export async function request(event, context) {
  const data = JSON.parse(event.body)
  const params = {
    TableName: process.env.maintanancesTable,
    Key: {
      requestId: event.pathParameters.requestId,
      // apartId: data.apartId
      requestedAt: data.requestedAt
    },
    UpdateExpression:
      "SET requestStatus = :requestStatus",
    ExpressionAttributeValues: {
      ":requestStatus": data.requestStatus + 1
    },
    ReturnValues: "ALL_NEW",
  }

  try {
    const result = await dynamoDbLib.call("update", params);
    return success(result);

  } catch (e) {
    console.log(e)
    return failure({ status: false, error: e });
  }
}
