Skip to content

Commit

Permalink
Converted to JS using rw ts-to-js
Browse files Browse the repository at this point in the history
  • Loading branch information
rushabhhere committed Aug 7, 2022
1 parent f133384 commit 830f28e
Show file tree
Hide file tree
Showing 71 changed files with 248 additions and 251 deletions.
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion api/src/functions/auth.ts → api/src/functions/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { db } from 'src/lib/db'
import { DbAuthHandler } from '@redwoodjs/api'

export const handler = async (event, context) => {

const forgotPasswordOptions = {
// handler() is invoked after verifying that a user was found with the given
// username. This is where you can send the user an email with a link to
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 3 additions & 4 deletions api/src/lib/auth.ts → api/src/lib/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,14 @@ export const getCurrentUser = async (session) => {
*
* @returns {boolean} - If the currentUser is authenticated
*/
export const isAuthenticated = (): boolean => {
export const isAuthenticated = () => {
return !!context.currentUser
}

/**
* When checking role membership, roles can be a single value, a list, or none.
* You can use Prisma enums too (if you're using them for roles), just import your enum type from `@prisma/client`
*/
type AllowedRoles = string | string[] | undefined

/**
* Checks if the currentUser is authenticated (and assigned one of the given roles)
Expand All @@ -49,7 +48,7 @@ type AllowedRoles = string | string[] | undefined
* @returns {boolean} - Returns true if the currentUser is logged in and assigned one of the given roles,
* or when no roles are provided to check against. Otherwise returns false.
*/
export const hasRole = (roles: AllowedRoles): boolean => {
export const hasRole = (roles) => {
if (!isAuthenticated()) {
return false
}
Expand Down Expand Up @@ -98,7 +97,7 @@ export const hasRole = (roles: AllowedRoles): boolean => {
*
* @see https://github.com/redwoodjs/redwood/tree/main/packages/auth for examples
*/
export const requireAuth = ({ roles }: { roles: AllowedRoles }) => {
export const requireAuth = ({ roles }) => {
if (!isAuthenticated()) {
throw new AuthenticationError("You don't have permission to do that.")
}
Expand Down
File renamed without changes.
File renamed without changes.
20 changes: 20 additions & 0 deletions api/src/services/contacts/contacts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { validate } from '@redwoodjs/api'

import { db } from 'src/lib/db'

export const contacts = () => {
return db.contact.findMany()
}

export const contact = ({ id }) => {
return db.contact.findUnique({
where: { id },
})
}

export const createContact = ({ input }) => {
validate(input.email, 'email', { email: true })
return db.contact.create({
data: input,
})
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import type { Prisma } from '@prisma/client'

export const standard = defineScenario<Prisma.ContactCreateArgs>({
export const standard = defineScenario({
contact: {
john: {
data: {
Expand All @@ -11,5 +9,3 @@ export const standard = defineScenario<Prisma.ContactCreateArgs>({
},
},
})

export type StandardScenario = typeof standard
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { contacts, contact, createContact } from './contacts'
import type { StandardScenario } from './contacts.scenarios'

// Generated boilerplate tests do not account for all circumstances
// and can fail without adjustments, e.g. Float and DateTime types.
Expand All @@ -8,13 +7,13 @@ import type { StandardScenario } from './contacts.scenarios'
// https://redwoodjs.com/docs/testing#jest-expect-type-considerations

describe('contacts', () => {
scenario('returns all contacts', async (scenario: StandardScenario) => {
scenario('returns all contacts', async (scenario) => {
const result = await contacts()

expect(result.length).toEqual(Object.keys(scenario.contact).length)
})

scenario('returns a single contact', async (scenario: StandardScenario) => {
scenario('returns a single contact', async (scenario) => {
const result = await contact({ id: scenario.contact.john.id })

expect(result).toEqual(scenario.contact.john)
Expand Down
24 changes: 0 additions & 24 deletions api/src/services/contacts/contacts.ts

This file was deleted.

30 changes: 30 additions & 0 deletions api/src/services/posts/posts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { db } from 'src/lib/db'

export const posts = () => {
return db.post.findMany()
}

export const post = ({ id }) => {
return db.post.findUnique({
where: { id },
})
}

export const createPost = ({ input }) => {
return db.post.create({
data: input,
})
}

export const updatePost = ({ id, input }) => {
return db.post.update({
data: input,
where: { id },
})
}

export const deletePost = ({ id }) => {
return db.post.delete({
where: { id },
})
}
6 changes: 6 additions & 0 deletions api/src/services/posts/posts.scenarios.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const standard = defineScenario({
post: {
one: { data: { title: 'String', body: 'String' } },
two: { data: { title: 'String', body: 'String' } },
},
})
10 changes: 0 additions & 10 deletions api/src/services/posts/posts.scenarios.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { posts, post, createPost, updatePost, deletePost } from './posts'
import type { StandardScenario } from './posts.scenarios'

// Generated boilerplate tests do not account for all circumstances
// and can fail without adjustments, e.g. Float and DateTime types.
Expand All @@ -8,13 +7,13 @@ import type { StandardScenario } from './posts.scenarios'
// https://redwoodjs.com/docs/testing#jest-expect-type-considerations

describe('posts', () => {
scenario('returns all posts', async (scenario: StandardScenario) => {
scenario('returns all posts', async (scenario) => {
const result = await posts()

expect(result.length).toEqual(Object.keys(scenario.post).length)
})

scenario('returns a single post', async (scenario: StandardScenario) => {
scenario('returns a single post', async (scenario) => {
const result = await post({ id: scenario.post.one.id })

expect(result).toEqual(scenario.post.one)
Expand All @@ -29,7 +28,7 @@ describe('posts', () => {
expect(result.body).toEqual('String')
})

scenario('updates a post', async (scenario: StandardScenario) => {
scenario('updates a post', async (scenario) => {
const original = await post({ id: scenario.post.one.id })
const result = await updatePost({
id: original.id,
Expand All @@ -39,7 +38,7 @@ describe('posts', () => {
expect(result.title).toEqual('String2')
})

scenario('deletes a post', async (scenario: StandardScenario) => {
scenario('deletes a post', async (scenario) => {
const original = await deletePost({ id: scenario.post.one.id })
const result = await post({ id: original.id })

Expand Down
32 changes: 0 additions & 32 deletions api/src/services/posts/posts.ts

This file was deleted.

File renamed without changes.
3 changes: 3 additions & 0 deletions scripts/seed.ts → scripts/seed.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ export default async () => {
title: 'Welcome to the blog!',
body: "I'm baby single- origin coffee kickstarter lo - fi paleo skateboard.Tumblr hashtag austin whatever DIY plaid knausgaard fanny pack messenger bag blog next level woke.Ethical bitters fixie freegan,helvetica pitchfork 90's tbh chillwave mustache godard subway tile ramps art party. Hammock sustainable twee yr bushwick disrupt unicorn, before they sold out direct trade chicharrones etsy polaroid hoodie. Gentrify offal hoodie fingerstache.",
},

{
id: 2,
title: 'A little more about me',
body: "Raclette shoreditch before they sold out lyft. Ethical bicycle rights meh prism twee. Tote bag ennui vice, slow-carb taiyaki crucifix whatever you probably haven't heard of them jianbing raw denim DIY hot chicken. Chillwave blog succulents freegan synth af ramps poutine wayfarers yr seitan roof party squid. Jianbing flexitarian gentrify hexagon portland single-origin coffee raclette gluten-free. Coloring book cloud bread street art kitsch lumbersexual af distillery ethical ugh thundercats roof party poke chillwave. 90's palo santo green juice subway tile, prism viral butcher selvage etsy pitchfork sriracha tumeric bushwick.",
},

{
id: 3,
title: 'What is the meaning of life?',
Expand Down Expand Up @@ -39,6 +41,7 @@ export default async () => {
'ad9563042fe9f154419361eeeb775d8a12f3975a3722953fd8e326dd108d5645',
salt: '1c99de412b219e9abf4665293211adce',
},

update: {},
})

Expand Down
File renamed without changes.
File renamed without changes.
36 changes: 32 additions & 4 deletions web/src/Routes.tsx → web/src/Routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,51 @@ const Routes = () => {
return (
<Router>
<Route path="/login" page={LoginPage} name="login" />

<Route path="/signup" page={SignupPage} name="signup" />
<Route path="/forgot-password" page={ForgotPasswordPage} name="forgotPassword" />
<Route path="/reset-password" page={ResetPasswordPage} name="resetPassword" />

<Route
path="/forgot-password"
page={ForgotPasswordPage}
name="forgotPassword"
/>

<Route
path="/reset-password"
page={ResetPasswordPage}
name="resetPassword"
/>

<Private unauthenticated="home">
<Set wrap={PostsLayout}>
<Route path="/admin/posts/new" page={PostNewPostPage} name="newPost" />
<Route path="/admin/posts/{id:Int}/edit" page={PostEditPostPage} name="editPost" />
<Route
path="/admin/posts/new"
page={PostNewPostPage}
name="newPost"
/>

<Route
path="/admin/posts/{id:Int}/edit"
page={PostEditPostPage}
name="editPost"
/>

<Route path="/admin/posts/{id:Int}" page={PostPostPage} name="post" />

<Route path="/admin/posts" page={PostPostsPage} name="posts" />
</Set>
</Private>

<Set wrap={BlogLayout}>
<Route path="/contact" page={ContactPage} name="contact" />

<Route path="/article/{id:Int}" page={ArticlePage} name="article" />

<Route path="/about" page={AboutPage} name="about" />

<Route path="/" page={HomePage} name="home" />
</Set>

<Route notfound page={NotFoundPage} />
</Router>
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
import type { Post } from 'types/graphql'

import { Link, routes } from '@redwoodjs/router'

interface Props {
article: Post
}

const Article = ({ article }: Props) => {
const Article = ({ article }) => {
return (
<article>
<header>
<h2 className="text-xl text-blue-700 font-semibold">
<Link to={routes.article({ id: article.id })}>{article.title}</Link>
</h2>
</header>

<div className="mt-2 text-gray-900 font-light">{article.body}</div>
</article>
)
Expand Down
File renamed without changes.
22 changes: 22 additions & 0 deletions web/src/components/ArticleCell/ArticleCell.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import Article from 'src/components/Article'

export const QUERY = gql`
query FindArticleQuery($id: Int!) {
article: post(id: $id) {
id
title
body
createdAt
}
}
`

export const Loading = () => <div>Loading...</div>

export const Empty = () => <div>Empty</div>

export const Failure = ({ error }) => <div>Error: {error.message}</div>

export const Success = ({ article }) => {
return <Article article={article} />
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Define your own mock data here:
export const standard = (/* vars, { ctx, req } */) => ({
export const standard = () => ({
article: {
id: 1,
title: 'First Post',
Expand Down
Loading

0 comments on commit 830f28e

Please sign in to comment.