Skip to content

Commit

Permalink
Merge branch 'main' into production
Browse files Browse the repository at this point in the history
  • Loading branch information
bnussman committed Oct 16, 2023
2 parents 2b1cc93 + a302e87 commit 53b3890
Show file tree
Hide file tree
Showing 9 changed files with 196 additions and 346 deletions.
14 changes: 7 additions & 7 deletions api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
"dependencies": {
"@apollo/server": "^4.9.4",
"@banksnussman/graphql-fields-to-relations": "^2.0.0",
"@mikro-orm/core": "5.8.8",
"@mikro-orm/postgresql": "5.8.8",
"@sentry/integrations": "^7.73.0",
"@sentry/node": "^7.73.0",
"@mikro-orm/core": "5.8.9",
"@mikro-orm/postgresql": "5.8.9",
"@sentry/integrations": "^7.74.0",
"@sentry/node": "^7.74.0",
"aws-sdk": "^2.1473.0",
"bcrypt": "^5.1.1",
"body-parser": "^1.20.2",
Expand All @@ -52,13 +52,13 @@
"ws": "^8.14.2"
},
"devDependencies": {
"@mikro-orm/cli": "5.8.8",
"@mikro-orm/migrations": "5.8.8",
"@mikro-orm/cli": "5.8.9",
"@mikro-orm/migrations": "5.8.9",
"@types/bcrypt": "^5.0.0",
"@types/body-parser": "^1.19.3",
"@types/cors": "^2.8.14",
"@types/express": "^4.17.19",
"@types/node": "^20.8.5",
"@types/node": "^20.8.6",
"@types/nodemailer": "^6.4.11",
"@types/uuid": "^9.0.5",
"@types/ws": "^8.5.7",
Expand Down
16 changes: 13 additions & 3 deletions api/src/rating/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,25 @@ export class RatingResolver {
}

@Mutation(() => Boolean)
@Authorized(UserRole.ADMIN)
@Authorized()
public async deleteRating(@Ctx() ctx: Context, @Arg('id') id: string): Promise<boolean> {
const rating = await ctx.em.findOneOrFail(Rating, id, { populate: ['rated'] });

if (!rating.rated.rating) throw new Error("You are trying to delete a rating for a user who's rating value is undefined");
if (ctx.user.role === UserRole.USER && rating.rater.id !== ctx.user.id) {
throw new Error("You can't delete a rating that you didn't create.");
}

if (!rating.rated.rating) {
throw new Error("You are trying to delete a rating for a user who's rating value is undefined");
}

const numberOfRatings = await ctx.em.count(Rating, { rated: rating.rated.id });

rating.rated.rating = numberOfRatings <= 1 ? undefined : rating.rated.rating = (rating.rated.rating * numberOfRatings - rating.stars) / (numberOfRatings - 1);
if (numberOfRatings <= 1) {
rating.rated.rating = undefined;
} else {
rating.rated.rating = (rating.rated.rating * numberOfRatings - rating.stars) / (numberOfRatings - 1);
}

ctx.em.persist(rating.rated);

Expand Down
14 changes: 4 additions & 10 deletions app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,25 +143,19 @@ function Beep() {
);
}

function App2() {
function App() {
return (
<GestureHandlerRootView style={{ flex: 1 }}>
<NativeBaseProvider
theme={NATIVE_BASE_THEME}
colorModeManager={colorModeManager}
>
<Beep />
<ApolloProvider client={client}>
<Beep />
</ApolloProvider>
</NativeBaseProvider>
</GestureHandlerRootView>
);
}

function App() {
return (
<ApolloProvider client={client}>
<App2 />
</ApolloProvider>
);
}

export default App;
53 changes: 49 additions & 4 deletions app/components/Rating.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,74 @@ import { Navigation } from "../utils/Navigation";
import { useUser } from "../utils/useUser";
import { Avatar } from "./Avatar";
import { printStars } from "./Stars";
import { Unpacked } from "../utils/constants";
import { Unpacked, isMobile } from "../utils/constants";
import { Card } from "./Card";
import { Alert } from "react-native";
import { ApolloError, gql, useMutation } from "@apollo/client";

type Rating = Unpacked<GetRatingsQuery["getRatings"]["items"]>;

interface Props {
item: Unpacked<GetRatingsQuery["getRatings"]["items"]>;
item: Rating;
index: number;
}

export const DeleteRating = gql`
mutation DeleteRating($id: String!) {
deleteRating(id: $id)
}
`;

export function Rating(props: Props) {
const { item } = props;
const { user } = useUser();
const navigation = useNavigation<Navigation>();
const otherUser = user?.id === item.rater.id ? item.rated : item.rater;

const isRater = user?.id === item.rater.id;
const isRated = user?.id === item.rated.id;

const [_deleteRating] = useMutation(DeleteRating);

const onLongPress = () => {
if (isMobile) {
Alert.alert(
"Delete Rating?",
"Are you sure you want to delete this rating?",
[
{
text: "No",
style: "cancel",
},
{ text: "Yes", onPress: deleteRating },
],
{ cancelable: true }
);
} else {
deleteRating();
}
};

const deleteRating = () => {
_deleteRating({
variables: { id: item.id },
update: (cache) => {
cache.evict({
id: cache.identify({
__typename: "Rating",
id: item.id,
}),
});
},
}).catch((error: ApolloError) => alert(error?.message));
};

return (
<Card
mt={2}
mx={1}
pressable
onPress={() => navigation.push("Profile", { id: otherUser.id })}
onLongPress={onLongPress}
>
<Stack space={2}>
<HStack alignItems="center" space={2}>
Expand All @@ -43,7 +88,7 @@ export function Rating(props: Props) {
{otherUser.name}
</Text>
<Text color="gray.400" fontSize="xs" isTruncated>
{`${isRater ? "Rated" : "Recieved"} - ${new Date(
{`${isRater ? "You rated" : "Rated you"} - ${new Date(
item.timestamp
).toLocaleString(undefined, { dateStyle: 'short', timeStyle: "short" })}`}
</Text>
Expand Down
2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"react-native-svg": "13.9.0",
"react-native-web": "~0.19.7",
"sentry-expo": "~7.0.1",
"styled-components": "^6.0.9",
"styled-components": "^6.1.0",
"styled-system": "^5.1.5"
},
"devDependencies": {
Expand Down
36 changes: 0 additions & 36 deletions app/routes/ride/StatusBar.tsx

This file was deleted.

24 changes: 0 additions & 24 deletions app/utils/OfflineToken.ts

This file was deleted.

Loading

0 comments on commit 53b3890

Please sign in to comment.