Skip to content

Instantly share code, notes, and snippets.

@tanveerprottoy
Created May 3, 2022 12:23
Show Gist options
  • Save tanveerprottoy/5177648cfac2eeb0b7b2ce59d5499dbf to your computer and use it in GitHub Desktop.
Save tanveerprottoy/5177648cfac2eeb0b7b2ce59d5499dbf to your computer and use it in GitHub Desktop.
app-provider.repository.ts
import { Injectable } from "@nestjs/common";
import { CreateAppDto } from "./create-app.dto";
import { App } from "./data/entities/app.entity";
import { v4 as uuidv4 } from 'uuid';
import { DbDataOpsInstance } from "./libs/dynamodb";
import { DeleteCommandInput, GetCommandInput, PutCommand, PutCommandInput, ScanCommandInput, UpdateCommandInput } from "@aws-sdk/lib-dynamodb";
import { Constants } from "./constants";
import { DbClientsProvider } from "./data/db-clients.provider";
@Injectable()
export class AppRepository {
constructor(
private readonly dbClientsProvider: DbClientsProvider
) { }
async createWithProvider(dto: CreateAppDto): Promise<App | null> {
try {
console.log(dto);
const { name } = dto;
const item = {
id: uuidv4(),
name
} as App;
const params: PutCommandInput = {
TableName: Constants.APPS_TABLE,
Item: item
};
const data = await this.dbClientsProvider.dbDocumentClient.send(
new PutCommand(params)
);
console.log(data);
if(data.$metadata.httpStatusCode == Constants.HTTP_200) {
return item;
}
return null;
}
catch(e) {
console.error(e);
return null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment