"use strict" ; import { AWSError , DynamoDB } from "aws-sdk" ; import { NurseParam } from "../lambda/definitions/types" ; import { Center } from "../lambda/definitions/types" ; export default class NurseTable { client : DynamoDB . DocumentClient ; constructor ( serviceClient ) { this . client = serviceClient ; } getNurses ( centerId ) { const params = { TableName : process . env . NURSE_TABLE_NAME ! , } ; return new Promise ( ( resolve , reject ) => { this . client . scan ( params , ( err , data ) => { if ( err ) { console . log ( err ) ; reject ( err ) ; } else { console . log ( "getNurse Success!" ) ; const filtered = data . Items ! . filter ( ( item ) => item . manageCenters . findIndex ( ( center ) => center . centerId === centerId ) > - 1 ) ; resolve ( { Count : filtered . length , Items : filtered } ) ; } } ) ; } ) ; } getNurse ( nurseId ) { const params = { TableName : process . env . NURSE_TABLE_NAME ! , Key : { nurseId : nurseId , } , } ; console . log ( params ) ; return new Promise ( ( resolve , reject ) => { this . client . get ( params , ( err , data ) => { if ( err ) { console . log ( err ) ; reject ( err ) ; } else { console . log ( "getNurse Success!" ) ; console . log ( data . Item ) ; resolve ( data . Item ! ) ; } } ) ; } ) ; } postNurse ( nurse ) { const params = { TableName : process . env . NURSE_TABLE_NAME ! , Item : nurse , } ; console . log ( params ) ; return new Promise ( ( resolve , reject ) => { this . client . put ( params , ( err , data ) => { console . log ( data ) ; if ( err ) { console . log ( err ) ; reject ( err ) ; } else { console . log ( "postNurse Success!" ) ; resolve ( nurse ) ; } } ) ; } ) ; } putNurse ( nurseId , body ) { const params = { TableName : process . env . NURSE_TABLE_NAME ! , Key : { nurseId : nurseId , } , UpdateExpression : "set manageCenters = :c" , ExpressionAttributeValues : { ":c" : body . manageCenters , } , } ; console . log ( params ) ; return new Promise ( ( resolve , reject ) => { this . client . update ( params , ( err , data ) => { console . log ( data ) ; if ( err ) { console . log ( err ) ; reject ( err ) ; } else { console . log ( "putNurse Success!" ) ; resolve ( { nurseId : nurseId , manageCenters : body . manageCenters } ) ; } } ) ; } ) ; } }