Skip to content

Commit

Permalink
fix mediaId
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernardo Vieira committed Mar 29, 2022
1 parent 5bfcd32 commit 5dde534
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 6 deletions.
4 changes: 3 additions & 1 deletion packages/api/src/controllers/community.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ class CommunityController {
email,
txReceipt,
contractParams,
coverMediaId,
coverMediaPath,
})
.then((community) => standardResponse(res, 201, true, community))
Expand Down Expand Up @@ -327,11 +328,12 @@ class CommunityController {
description,
currency,
// should be temporary
coverMediaId,
coverMediaPath: coverMediaPath as any,
email,
},
req.user?.address,
req.user?.userId,
req.user?.userId
)
.then((community) =>
standardResponse(res, 200, true, community)
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/controllers/story.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class StoryController {
.add(req.user.address, {
communityId,
message,
storyMediaId,
storyMediaPath,
})
.then((r) => standardResponse(res, 200, true, r))
Expand Down
2 changes: 2 additions & 0 deletions packages/api/src/controllers/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class UserController {
username,
year,
children,
avatarMediaId,
avatarMediaPath,
trust: {
phone,
Expand Down Expand Up @@ -145,6 +146,7 @@ class UserController {
);
services.app.UserService.updateAvatar(
req.user.address,
mediaId,
avatarMediaPath
)
.then((r) => standardResponse(res, 201, r, ''))
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/services/app/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,11 @@ export default class UserService {

public static async updateAvatar(
address: string,
avatarMediaId: number,
avatarMediaPath: string
): Promise<boolean> {
const updated = await this.appUser.update(
{ avatarMediaPath },
{ avatarMediaId, avatarMediaPath },
{ returning: true, where: { address } }
);
return updated[0] > 0;
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/services/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export interface IUserAuth extends IUserHello {
export interface IAddStory {
byAddress?: string;
communityId?: number;
storyMediaId?: number;
storyMediaPath?: string;
message?: string;
}
Expand Down
15 changes: 13 additions & 2 deletions packages/core/src/services/story.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,22 @@ export default class StoryService {
fromAddress: string,
story: IAddStory
): Promise<ICommunityStory> {
let storyContentToAdd: { storyMediaPath?: string; message?: string } = {};
let storyContentToAdd: {
storyMediaPath?: string;
storyMediaId?: number;
message?: string;
} = {};
if (story.storyMediaPath) {
storyContentToAdd = {
storyMediaPath: story.storyMediaPath,
};
}
if (story.storyMediaId) {
storyContentToAdd = {
...storyContentToAdd,
storyMediaId: story.storyMediaId,
};
}
let storyCommunityToAdd: {
storyCommunity?: StoryCommunityCreationEager[];
} = {};
Expand Down Expand Up @@ -368,7 +378,8 @@ export default class StoryService {
id: content.storyCommunity!.communityId,
name: content.storyCommunity!.community!.name,
cover: content.storyCommunity!.community!.cover!,
coverMediaPath: content.storyCommunity!.community!.coverMediaPath!,
coverMediaPath:
content.storyCommunity!.community!.coverMediaPath!,
story: {
id: content.id,
media: content.media,
Expand Down
21 changes: 19 additions & 2 deletions packages/core/src/services/ubi/community.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export default class CommunityService {
email,
txReceipt,
contractParams,
coverMediaId,
coverMediaPath,
}: ICommunityCreationAttributes): Promise<Community> {
let managerAddress: string = '';
Expand All @@ -105,6 +106,7 @@ export default class CommunityService {
country,
gps,
email,
coverMediaId,
coverMediaPath,
visibility: 'public', // will be changed if private
status: 'pending', // will be changed if private
Expand Down Expand Up @@ -192,15 +194,30 @@ export default class CommunityService {
description: string;
currency: string;
coverMediaPath: string;
coverMediaId: number;
email?: string;
},
userAddress?: string,
userId?: number
): Promise<CommunityAttributes> {
// since cover can't be null, we first update and then remove
const { name, description, currency, coverMediaPath, email } = params;
const {
name,
description,
currency,
coverMediaId,
coverMediaPath,
email,
} = params;
const update = await this.community.update(
{ name, description, currency, email, coverMediaPath },
{
name,
description,
currency,
email,
coverMediaId,
coverMediaPath,
},
{ where: { id } }
);
if (update[0] === 0) {
Expand Down

0 comments on commit 5dde534

Please sign in to comment.