Skip to content

Commit

Permalink
feat: added logourl in connection
Browse files Browse the repository at this point in the history
Signed-off-by: bhavanakarwade <bhavana.karwade@ayanworks.com>
Signed-off-by: KulkarniShashank <shashank.kulkarni@ayanworks.com>
  • Loading branch information
bhavanakarwade authored and KulkarniShashank committed Sep 11, 2024
1 parent 16128c4 commit 974e2e5
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 24 deletions.
4 changes: 4 additions & 0 deletions apps/api-gateway/src/connection/dtos/connection.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ export class ConnectionDto {
@IsOptional()
role: string;

@ApiPropertyOptional()
@IsOptional()
imageUrl: string;

@ApiPropertyOptional()
@IsOptional()
autoAcceptConnection: boolean;
Expand Down
23 changes: 20 additions & 3 deletions apps/connection/src/connection.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,26 @@ export class ConnectionRepository {
});
return agentDetails;

} catch (error) {
this.logger.error(`Error in saveConnectionWebhook: ${error.message} `);
throw error;
const agentDetails = await this.prisma.connections.upsert({
where: {
connectionId: connectionDto?.id
},
update: {
lastChangedDateTime: connectionDto?.lastChangedDateTime,
lastChangedBy: organisationId,
imageUrl: connectionDto.imageUrl,
state: connectionDto?.state
},
create: {
createDateTime: connectionDto?.createDateTime,
lastChangedDateTime: connectionDto?.lastChangedDateTime,
createdBy: organisationId,
lastChangedBy: organisationId,
imageUrl: connectionDto.imageUrl,
connectionId: connectionDto?.id,
state: connectionDto?.state,
theirLabel: maskedTheirLabel,
orgId: organisationId
}
});
return agentDetails;
Expand Down
2 changes: 1 addition & 1 deletion apps/connection/src/connection.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class ConnectionService {

let logoImageUrl;
if (organisation.logoUrl) {
logoImageUrl = `${process.env.API_GATEWAY_PROTOCOL}://${process.env.API_ENDPOINT}/orgs/profile/${organisation.id}`;
logoImageUrl = organisation.logoUrl;
}

const connectionPayload = {
Expand Down
1 change: 1 addition & 0 deletions apps/connection/src/interfaces/connection.interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export interface ICreateConnectionPayload {
lastChangedDateTime: string;
id: string;
state: string;
imageUrl: string;
orgDid?: string;
theirLabel: string;
autoAcceptConnection: boolean;
Expand Down
31 changes: 17 additions & 14 deletions apps/organization/src/organization.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// eslint-disable-next-line camelcase
import { organisation, org_roles, user } from '@prisma/client';
/* eslint-disable prefer-destructuring */
import { organisation, user } from '@prisma/client';
import { Injectable, Logger, ConflictException, InternalServerErrorException, HttpException, BadRequestException, ForbiddenException } from '@nestjs/common';
import { PrismaService } from '@credebl/prisma-service';
import { CommonService } from '@credebl/common';
Expand Down Expand Up @@ -61,9 +61,7 @@ export class OrganizationService {
createOrgDto.createdBy = userId;
createOrgDto.lastChangedBy = userId;

const allowedExtensions = ['png', 'jpg', 'jpeg'];

const imageUrl = await this.uploadFileToS3(createOrgDto.logo, allowedExtensions);
const imageUrl = await this.uploadFileToS3(createOrgDto.logo);

if (imageUrl) {
createOrgDto.logo = imageUrl;
Expand Down Expand Up @@ -91,17 +89,14 @@ export class OrganizationService {
}
}

//
async uploadFileToS3(orgLogo: string, allowedExtensions: string[]): Promise<string> {
async uploadFileToS3(orgLogo: string): Promise<string> {
try {
const ext = allowedExtensions.find(extension => orgLogo.endsWith(`.${extension}`)) || 'png';
const imgData = Buffer.from(orgLogo, 'base64');
// const imageData = converBase64ToImage(base64, pathToSaveImage)
// const logoUrl = await this.awsService.uploadUserCertificate(imgData, ext, 'orgLogo', process.env.AWS_ORG_LOGO_BUCKET_NAME,
// 'base64', 'orgLogos');

const updatedOrglogo = orgLogo.split(',')[1];
const imgData = Buffer.from(updatedOrglogo, 'base64');
const logoUrl = await this.awsService.uploadUserCertificate(
imgData,
ext,
'png',
'orgLogo',
process.env.AWS_ORG_LOGO_BUCKET_NAME,
'base64',
Expand Down Expand Up @@ -148,7 +143,15 @@ export class OrganizationService {

const orgSlug = await this.createOrgSlug(updateOrgDto.name);
updateOrgDto.orgSlug = orgSlug;
updateOrgDto.userId = userId;
updateOrgDto.userId = userId;
const imageUrl = await this.uploadFileToS3(updateOrgDto.logo);

if (imageUrl) {
updateOrgDto.logo = imageUrl;
} else {
throw new BadRequestException('error in uploading image on s3 bucket');
}

const organizationDetails = await this.organizationRepository.updateOrganization(updateOrgDto);
await this.userActivityService.createActivity(userId, organizationDetails.id, `${organizationDetails.name} organization updated`, 'Organization details updated successfully');
return organizationDetails;
Expand Down
11 changes: 5 additions & 6 deletions libs/aws/src/aws.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class AwsService {
}

async uploadUserCertificate(
fileBuffer: Buffer | string,
fileBuffer: Buffer,
ext: string,
filename: string,
bucketName: string,
Expand All @@ -33,21 +33,20 @@ export class AwsService {
): Promise<string> {
const timestamp = Date.now();
const putObjectAsync = promisify(this.s4.putObject).bind(this.s4);

try {
await putObjectAsync({
Bucket: bucketName,
// Bucket: process.env.AWS_PUBLIC_BUCKET_NAME,
Bucket: `${process.env.AWS_ORG_LOGO_BUCKET_NAME}`,
Key: `${pathAWS}/${encodeURIComponent(filename)}-${timestamp}.png`,
Body: fileBuffer,
ContentEncoding: encoding,
ContentType: `image/png`
// ContentType: ext
});

const imageUrl = `https://${process.env.AWS_ORG_LOGO_BUCKET_NAME}.s3.${process.env.AWS_PUBLIC_REGION}.amazonaws.com/${pathAWS}/${encodeURIComponent(filename)}-${timestamp}.${ext}`;
return imageUrl;
} catch (err) {
throw new HttpException(err, HttpStatus.SERVICE_UNAVAILABLE);
} catch (error) {
throw new HttpException(error, HttpStatus.SERVICE_UNAVAILABLE);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "connections" ADD COLUMN "imageUrl" TEXT;
1 change: 1 addition & 0 deletions libs/prisma-service/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ model connections {
createdBy String @db.Uuid
lastChangedDateTime DateTime @default(now()) @db.Timestamptz(6)
lastChangedBy String @db.Uuid
imageUrl String?
connectionId String @unique
theirLabel String @default("")
state String
Expand Down

0 comments on commit 974e2e5

Please sign in to comment.