Skip to content

Commit

Permalink
Add permission for edit and remove
Browse files Browse the repository at this point in the history
  • Loading branch information
Prabhat Pal committed Feb 7, 2021
1 parent 6e4adeb commit 21399ee
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 26 deletions.
34 changes: 19 additions & 15 deletions pages/places/[id]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import ViewPlaceMap from "src/components/ViewPlaceMap";
import CloudinaryImage from "src/components/ui/CloudinaryImage";
import Layout from "src/components/Layout";
import { ViewState } from "react-map-gl";
import { useAuth } from "src/contexts";

type PlaceIdFC<P = {}> = FC<P> & additionalType;

Expand All @@ -33,6 +34,7 @@ const PlaceId: PlaceIdFC = () => {
longitude: -122.3321,
zoom: 13,
});
const { user } = useAuth();
const { addToast } = useToasts();
const router = useRouter();

Expand Down Expand Up @@ -133,21 +135,23 @@ const PlaceId: PlaceIdFC = () => {
>
<IoChevronBack className="text-2xl" />
</Button>
<div className="space-x-4">
<Button
className="text-2xl"
onClick={() => setEditMode(true)}
>
<MdEdit />
</Button>
<Button
variant="danger"
className="text-2xl"
onClick={() => setShowDeleteModal(true)}
>
<MdDelete />
</Button>
</div>
{!!user && user.uid === place.userId ? (
<div className="space-x-4">
<Button
className="text-2xl"
onClick={() => setEditMode(true)}
>
<MdEdit />
</Button>
<Button
variant="danger"
className="text-2xl"
onClick={() => setShowDeleteModal(true)}
>
<MdDelete />
</Button>
</div>
) : null}
</>
)}
</div>
Expand Down
2 changes: 1 addition & 1 deletion schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type Place {
placeName: String!
placeType: String!
publicId: String!
userId: String!
}

input PlaceInput {
Expand All @@ -48,7 +49,6 @@ input PlaceInput {
}

type Query {
hello: String!
place(id: String!): Place
places(bounds: BoundInput!): [Place!]
}
1 change: 1 addition & 0 deletions src/generated/GetPlaceByIdQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface GetPlaceByIdQuery_place_nearby {
export interface GetPlaceByIdQuery_place {
__typename: "Place";
id: string;
userId: string;
latitude: number;
longitude: number;
address: string;
Expand Down
1 change: 1 addition & 0 deletions src/generated/GetPlacesQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { BoundInput } from "./globalTypes";
export interface GetPlacesQuery_places {
__typename: "Place";
id: string;
userId: string;
latitude: number;
longitude: number;
address: string;
Expand Down
2 changes: 2 additions & 0 deletions src/gql/place.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export const GET_PLACE_BY_ID_QUERY = gql`
query GetPlaceByIdQuery($id: String!) {
place(id: $id) {
id
userId
latitude
longitude
address
Expand All @@ -25,6 +26,7 @@ export const GET_PLACES_QUERY = gql`
query GetPlacesQuery($bounds: BoundInput!) {
places(bounds: $bounds) {
id
userId
latitude
longitude
address
Expand Down
12 changes: 2 additions & 10 deletions src/schema/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
import { buildSchemaSync, Query, Resolver } from "type-graphql";
import { buildSchemaSync } from "type-graphql";
import { authChecker } from "./authChecker";
import { ImageResolver } from "./image";
import { PlaceResolver } from "./place";

@Resolver()
class DummyResolver {
@Query((_returns) => String)
hello() {
return "Hello world";
}
}

export const schema = buildSchemaSync({
resolvers: [DummyResolver, ImageResolver, PlaceResolver],
resolvers: [ImageResolver, PlaceResolver],
emitSchemaFile: process.env.NODE_ENV === "development",
authChecker,
});
3 changes: 3 additions & 0 deletions src/schema/place.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ class Place {
@Field((_type) => ID)
id!: number;

@Field((_type) => String)
userId!: string;

@Field((_type) => String)
placeName!: string;

Expand Down

1 comment on commit 21399ee

@vercel
Copy link

@vercel vercel bot commented on 21399ee Feb 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.