Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix mediaId #238

Merged
merged 2 commits into from
Mar 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
13 changes: 9 additions & 4 deletions packages/core/tests/integration/community.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1611,7 +1611,8 @@ describe('community service', () => {
currency: communities[0].currency,
description: communityNewDescription,
name: communities[0].name,
coverMediaPath: "cover/image.jpg",
coverMediaId: 1,
coverMediaPath: 'cover/image.jpg',
}
);

Expand Down Expand Up @@ -1651,7 +1652,8 @@ describe('community service', () => {
currency: communities[0].currency,
description: communityNewDescription,
name: communities[0].name,
coverMediaPath: "cover/image2.jpg",
coverMediaId: 1,
coverMediaPath: 'cover/image2.jpg',
}
);

Expand Down Expand Up @@ -1694,7 +1696,8 @@ describe('community service', () => {
currency: communities[0].currency,
description: communityNewDescription,
name: communities[0].name,
coverMediaPath: "cover/image.jpg",
coverMediaId: 1,
coverMediaPath: 'cover/image.jpg',
email: 'test@gmail.com',
},
manager[0].address
Expand All @@ -1703,7 +1706,9 @@ describe('community service', () => {
expect(updatedCommunity.description).to.be.equal(
communityNewDescription
);
expect(updatedCommunity.coverMediaPath).to.be.equal('cover/image.jpg');
expect(updatedCommunity.coverMediaPath).to.be.equal(
'cover/image.jpg'
);
expect(updatedCommunity.email).to.be.equal('test@gmail.com');
});
});
Expand Down
2 changes: 2 additions & 0 deletions packages/core/tests/integration/user.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,7 @@ describe('user service', () => {
name: communities[0].name,
description: communities[0].description,
currency: communities[0].currency,
coverMediaId: communities[0].coverMediaId,
coverMediaPath: communities[0].coverMediaPath,
email: communities[0].email,
},
Expand Down Expand Up @@ -916,6 +917,7 @@ describe('user service', () => {
name: communities[0].name,
description: communities[0].description,
currency: communities[0].currency,
coverMediaId: communities[0].coverMediaId,
coverMediaPath: communities[0].coverMediaPath,
email: communities[0].email,
},
Expand Down