Skip to content

Commit

Permalink
Merge branch 'main' into app-reports
Browse files Browse the repository at this point in the history
  • Loading branch information
michalstruck committed Dec 12, 2024
2 parents af50fe1 + b7d09a4 commit c9b0c64
Show file tree
Hide file tree
Showing 110 changed files with 4,008 additions and 1,272 deletions.
13 changes: 5 additions & 8 deletions hasura/metadata/databases/default/tables/public_app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ insert_permissions:
check: {}
columns:
- engine
- id
- is_staging
- name
- team_id
- role: user
permission:
Expand All @@ -57,12 +57,6 @@ insert_permissions:
- role:
_eq: ADMIN
columns:
- description_internal
- engine
- is_archived
- is_staging
- name
- status
- team_id
select_permissions:
- role: api_key
Expand Down Expand Up @@ -93,6 +87,8 @@ select_permissions:
- is_archived
- is_banned
- is_staging
- rating_count
- rating_sum
- status
- team_id
filter: {}
Expand Down Expand Up @@ -133,13 +129,14 @@ update_permissions:
permission:
columns:
- is_banned
- rating_count
- rating_sum
filter: {}
check: null
comment: ""
- role: user
permission:
columns:
- description_internal
- is_archived
- status
filter:
Expand Down
64 changes: 42 additions & 22 deletions hasura/metadata/databases/default/tables/public_app_metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,16 @@ insert_permissions:
- app_mode
- app_website_url
- associated_domains
- can_import_all_contacts
- category
- contracts
- description
- hero_image_url
- id
- integration_url
- is_allowed_unlimited_notifications
- is_developer_allow_listing
- logo_img_url
- max_notifications_per_day
- name
- permit2_tokens
- short_name
Expand All @@ -86,8 +88,6 @@ insert_permissions:
- whitelisted_addresses
- world_app_button_text
- world_app_description
- is_allowed_unlimited_notifications
- max_notifications_per_day
comment: ""
- role: user
permission:
Expand All @@ -109,30 +109,11 @@ insert_permissions:
columns:
- app_id
- app_mode
- app_website_url
- associated_domains
- can_import_all_contacts
- category
- contracts
- description
- hero_image_url
- integration_url
- is_developer_allow_listing
- logo_img_url
- name
- permit2_tokens
- short_name
- showcase_img_urls
- source_code_url
- support_link
- supported_countries
- supported_languages
- verification_status
- whitelisted_addresses
- world_app_button_text
- world_app_description
- is_allowed_unlimited_notifications
- max_notifications_per_day
select_permissions:
- role: api_key
permission:
Expand Down Expand Up @@ -357,6 +338,45 @@ update_permissions:
_in:
- changes_requested
- verified
- role: service
permission:
columns:
- app_mode
- app_website_url
- associated_domains
- can_import_all_contacts
- category
- contracts
- created_at
- description
- hero_image_url
- integration_url
- is_allowed_unlimited_notifications
- is_developer_allow_listing
- is_reviewer_app_store_approved
- is_reviewer_world_app_approved
- is_row_verified
- logo_img_url
- max_notifications_per_day
- name
- permit2_tokens
- review_message
- reviewed_by
- short_name
- showcase_img_urls
- source_code_url
- support_link
- supported_countries
- supported_languages
- updated_at
- verification_status
- verified_at
- whitelisted_addresses
- world_app_button_text
- world_app_description
filter: {}
check: null
comment: ""
- role: user
permission:
columns:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,22 @@ select_permissions:
_eq: X-Hasura-User-Id
comment: ""
update_permissions:
- role: user
- role: service
permission:
columns:
- app_metadata_id
- description
- locale
- name
- short_name
- world_app_button_text
- world_app_description
filter: {}
check: null
comment: ""
- role: user
permission:
columns: []
filter:
app_metadata:
_and:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ALTER TABLE app
DROP COLUMN IF EXISTS rating_sum;

ALTER TABLE app
DROP COLUMN IF EXISTS rating_count;
26 changes: 26 additions & 0 deletions hasura/migrations/default/1733533994467_compute_ratings/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
-- Step 1: Add new columns for the total rating sum and total number of ratings
ALTER TABLE app
ADD COLUMN IF NOT EXISTS rating_sum BIGINT DEFAULT 0;

ALTER TABLE app
ADD COLUMN IF NOT EXISTS rating_count BIGINT DEFAULT 0;

-- Step 2: Update the new columns with the sum of ratings and count of ratings for each app
UPDATE app
SET
rating_sum = (
SELECT
COALESCE(SUM(rating), 0)
FROM
app_reviews
WHERE
app_reviews.app_id = app.id
),
rating_count = (
SELECT
COUNT(*)
FROM
app_reviews
WHERE
app_reviews.app_id = app.id
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
ALTER TABLE "public"."app"
ALTER COLUMN "rating_count" TYPE bigint;

ALTER TABLE "public"."app"
ALTER COLUMN "rating_sum" TYPE bigint;

alter table "public"."app"
alter column "rating_sum"
drop not null;

alter table "public"."app"
alter column "rating_count"
drop not null;
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
ALTER TABLE "public"."app"
ALTER COLUMN "rating_sum" TYPE int4;

ALTER TABLE "public"."app"
ALTER COLUMN "rating_count" TYPE int4;

alter table "public"."app"
alter column "rating_sum"
set
not null;

alter table "public"."app"
alter column "rating_count"
set
not null;
5 changes: 0 additions & 5 deletions web/api/helpers/app-rating/graphql/get-app-rating.graphql

This file was deleted.

63 changes: 0 additions & 63 deletions web/api/helpers/app-rating/index.ts

This file was deleted.

11 changes: 7 additions & 4 deletions web/api/helpers/app-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ export const formatAppMetadata = async (
(stat) => stat.app_id === appMetadata.app_id,
);

// const appRating = await getAppRating(appMetadata.app_id);

const appRating = 0;
const appRating =
appData.app.rating_count > 0
? parseFloat(
(appData.app.rating_sum / appData.app.rating_count).toFixed(2),
)
: 0;

const localisedContent = appMetadata.localisations?.[0];

Expand Down Expand Up @@ -51,7 +54,7 @@ export const formatAppMetadata = async (
return {
...appMetadataWithoutLocalisations,
name: name,
app_rating: appRating,
app_rating: appRating ?? 0,
world_app_button_text:
localisedContent?.world_app_button_text ??
appMetadata.world_app_button_text,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,25 @@ import * as Types from "@/graphql/graphql";
import { GraphQLClient, RequestOptions } from "graphql-request";
import gql from "graphql-tag";
type GraphQLClientRequestHeaders = RequestOptions["requestHeaders"];
export type GetAppRatingQueryVariables = Types.Exact<{
export type GetAppReviewQueryVariables = Types.Exact<{
app_id: Types.Scalars["String"]["input"];
nullifier_hash: Types.Scalars["String"]["input"];
}>;

export type GetAppRatingQuery = {
export type GetAppReviewQuery = {
__typename?: "query_root";
app_metadata: Array<{
__typename?: "app_metadata";
app_rating?: number | null;
}>;
app_reviews: Array<{ __typename?: "app_reviews"; rating: number }>;
};

export const GetAppRatingDocument = gql`
query GetAppRating($app_id: String!) {
app_metadata(where: { app_id: { _eq: $app_id } }) {
app_rating
export const GetAppReviewDocument = gql`
query GetAppReview($app_id: String!, $nullifier_hash: String!) {
app_reviews(
where: {
nullifier_hash: { _eq: $nullifier_hash }
app_id: { _eq: $app_id }
}
) {
rating
}
}
`;
Expand All @@ -43,17 +46,17 @@ export function getSdk(
withWrapper: SdkFunctionWrapper = defaultWrapper,
) {
return {
GetAppRating(
variables: GetAppRatingQueryVariables,
GetAppReview(
variables: GetAppReviewQueryVariables,
requestHeaders?: GraphQLClientRequestHeaders,
): Promise<GetAppRatingQuery> {
): Promise<GetAppReviewQuery> {
return withWrapper(
(wrappedRequestHeaders) =>
client.request<GetAppRatingQuery>(GetAppRatingDocument, variables, {
client.request<GetAppReviewQuery>(GetAppReviewDocument, variables, {
...requestHeaders,
...wrappedRequestHeaders,
}),
"GetAppRating",
"GetAppReview",
"query",
variables,
);
Expand Down
Loading

0 comments on commit c9b0c64

Please sign in to comment.