Skip to content

Commit

Permalink
[SOA-24] Review linting configuration (#29)
Browse files Browse the repository at this point in the history
* chore πŸ—οΈ (format): add prettierignore until address linting issues

* chore πŸ—οΈ (format):address linting warns

* fix βœ… (tests): correction to re-used constant
  • Loading branch information
mariadriana-deemaze authored Nov 15, 2024
1 parent 85388b4 commit 328ca63
Show file tree
Hide file tree
Showing 43 changed files with 119 additions and 98 deletions.
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build/**
database/migrations/**
README.md
35 changes: 16 additions & 19 deletions app/controllers/post_reactions_controller.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,35 @@
import PostReactionService from '#services/post_reaction_service';
import { errorsReducer } from '#utils/index';
import { postReactionValidator } from '#validators/post';
import { inject } from '@adonisjs/core';
import PostReactionService from '#services/post_reaction_service'
import { errorsReducer } from '#utils/index'
import { postReactionValidator } from '#validators/post'
import { inject } from '@adonisjs/core'
import type { HttpContext } from '@adonisjs/core/http'
import { errors } from '@vinejs/vine';
import { errors } from '@vinejs/vine'

@inject()
export default class PostReactionsController {

constructor(
private readonly service: PostReactionService
) { }
constructor(private readonly service: PostReactionService) {}

async create(ctx: HttpContext) {
const postId = ctx.params.id;
const userId = ctx.auth.user?.id!;
const payload = ctx.request.body();
const postId = ctx.params.id
const userId = ctx.auth.user?.id!
const payload = ctx.request.body()
try {
const { reaction } = await postReactionValidator.validate(payload)
const [preExistant, resource] = await this.service.create(userId, postId, reaction);
return preExistant ? ctx.response.ok(resource) : ctx.response.created(resource);
const [preExistant, resource] = await this.service.create(userId, postId, reaction)
return preExistant ? ctx.response.ok(resource) : ctx.response.created(resource)
} catch (error) {
if (error instanceof errors.E_VALIDATION_ERROR) {
const reducedErrors = errorsReducer(error.messages)
return ctx.response.badRequest(reducedErrors);
return ctx.response.badRequest(reducedErrors)
}
return ctx.response.badRequest();
return ctx.response.badRequest()
}
}

async destroy(ctx: HttpContext) {
const postId = ctx.params.id;
const userId = ctx.auth.user?.id!;
await this.service.destroy(userId, postId);
const postId = ctx.params.id
const userId = ctx.auth.user?.id!
await this.service.destroy(userId, postId)
return ctx.response.noContent()
}
}
4 changes: 2 additions & 2 deletions app/controllers/posts_controller.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { inject } from '@adonisjs/core'
import { errors } from '@vinejs/vine'
import type { HttpContext } from '@adonisjs/core/http'
import service from '#services/posts_service'
import PostsService from '#services/posts_service'
import policy from '#policies/posts_policy'
import Post from '#models/post'
import { errorsReducer } from '#utils/index'
Expand All @@ -10,7 +10,7 @@ import { PageObject } from '@adonisjs/inertia/types'

@inject()
export default class PostsController {
constructor(private service: service) {}
constructor(private service: PostsService) {}

async show(ctx: HttpContext): Promise<
| string
Expand Down
2 changes: 1 addition & 1 deletion app/interfaces/attachment.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AttachmentType } from '#models/attachment'
import { UUID } from 'crypto'
import { UUID } from 'node:crypto'

export interface AttachmentMetadataJSON {
filename: string
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions app/interfaces/post.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BaseEntity } from 'app/interfaces/base-entity'
import { UUID } from 'crypto'
import { BaseEntity } from '#interfaces/base_entity'
import { UUID } from 'node:crypto'
import { UserResponse } from './user'
import { AttachmentResponse } from 'app/interfaces/attachment'
import { PostReactionType } from '#enums/post'
Expand All @@ -25,8 +25,8 @@ export interface PostResponse extends BaseEntity {
user: UserResponse
link: LinkResponse | null
reactions: {
reacted: PostReactionType | null,
reacted: PostReactionType | null
reactionsCounts: Record<PostReactionType, number>
total:number;
total: number
}
}
4 changes: 2 additions & 2 deletions app/interfaces/user.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AttachmentResponse } from '#interfaces/attachment'
import { AccountRole } from '#models/user'
import { BaseEntity } from 'app/interfaces/base-entity'
import { UUID } from 'crypto'
import { BaseEntity } from '#interfaces/base_entity'
import { UUID } from 'node:crypto'

export interface UserResponse extends BaseEntity {
id: UUID
Expand Down
2 changes: 1 addition & 1 deletion app/models/attachment.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DateTime } from 'luxon'
import { BaseModel, column } from '@adonisjs/lucid/orm'
import type { UUID } from 'crypto'
import type { UUID } from 'node:crypto'
import { AttachmentMetadataJSON } from 'app/interfaces/attachment'

export enum AttachmentProvider {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DateTime } from 'luxon'
import { BaseModel, column } from '@adonisjs/lucid/orm'
import { LinkMetadataJSONResponse } from 'app/interfaces/post'
import type { UUID } from 'crypto'
import type { UUID } from 'node:crypto'

export class LinkMetadataJSON {
// TODO: Could benefit in adding class-validator?
Expand Down
4 changes: 2 additions & 2 deletions app/models/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { extractFirstLink, sanitizePostContent } from '#utils/index'
import PostReaction from '#models/post_reaction'
import PostReport from '#models/post_report'
import { PostStatus } from '#enums/post'
import type { UUID } from 'crypto'
import type { UUID } from 'node:crypto'
import type { BelongsTo, HasMany } from '@adonisjs/lucid/types/relations'

export default class Post extends BaseModel {
Expand Down Expand Up @@ -57,7 +57,7 @@ export default class Post extends BaseModel {
}

@beforeDelete()
public static async deleteAssociations(post: Post) {
static async deleteAssociations(post: Post) {
await post.related('reactions').query().delete()
}
}
2 changes: 1 addition & 1 deletion app/models/post_reaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Post from '#models/post'
import User from '#models/user'
import { PostReactionType } from '#enums/post'
import type { BelongsTo } from '@adonisjs/lucid/types/relations'
import type { UUID } from 'crypto'
import type { UUID } from 'node:crypto'

export default class PostReaction extends BaseModel {
@column({ isPrimary: true })
Expand Down
2 changes: 1 addition & 1 deletion app/models/post_report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { PostReportReason, PostReportStatus, PostStatus } from '#enums/post'
import User from '#models/user'
import Post from '#models/post'
import type { BelongsTo } from '@adonisjs/lucid/types/relations'
import type { UUID } from 'crypto'
import type { UUID } from 'node:crypto'

export default class PostReport extends BaseModel {
@column({ isPrimary: true })
Expand Down
2 changes: 1 addition & 1 deletion app/models/session.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BaseModel, column } from '@adonisjs/lucid/orm'
import { DateTime } from 'luxon'
import type { UUID } from 'crypto'
import type { UUID } from 'node:crypto'

export default class Session extends BaseModel {
@column({ isPrimary: true })
Expand Down
2 changes: 1 addition & 1 deletion app/models/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { BaseModel, column, hasMany } from '@adonisjs/lucid/orm'
import type { HasMany } from '@adonisjs/lucid/types/relations'
import { withAuthFinder } from '@adonisjs/auth/mixins/lucid'
import { DbRememberMeTokensProvider } from '@adonisjs/auth/session'
import { randomUUID, type UUID } from 'crypto'
import { randomUUID, type UUID } from 'node:crypto'
import Session from '#models/session'
import Post from '#models/post'

Expand Down
2 changes: 1 addition & 1 deletion app/services/attachment_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { MultipartFile } from '@adonisjs/core/bodyparser'
import { cuid } from '@adonisjs/core/helpers'
import drive from '@adonisjs/drive/services/main'
import { AttachmentResponse } from 'app/interfaces/attachment'
import { UUID } from 'crypto'
import { UUID } from 'node:crypto'

export default class AttachmentService {
private readonly disk = drive.use()
Expand Down
4 changes: 2 additions & 2 deletions app/services/link_parser_service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import LinkMetadata from '#models/link-metadata'
import LinkMetadata from '#models/link_metadata'
import { LinkResponse } from 'app/interfaces/post'
import { differenceInHours } from 'date-fns'
import env from '#start/env'
Expand Down Expand Up @@ -26,7 +26,7 @@ export default class LinkParserService {
body: JSON.stringify({ q: link }),
})
.then((res) => {
if (res.status != 200) {
if (res.status !== 200) {
console.log(res.status)
throw new Error('something went wrong')
}
Expand Down
2 changes: 1 addition & 1 deletion app/services/post_reaction_service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PostReactionType } from '#enums/post'
import PostReaction from '#models/post_reaction'
import type { UUID } from 'crypto'
import type { UUID } from 'node:crypto'

export default class PostReactionService {
constructor() {}
Expand Down
2 changes: 1 addition & 1 deletion app/services/post_report_service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Post from '#models/post'
import PostReport from '#models/post_report'
import { postReportValidator } from '#validators/post_report'
import { UUID } from 'crypto'
import { UUID } from 'node:crypto'

export default class PostReportService {
constructor() {}
Expand Down
4 changes: 2 additions & 2 deletions app/services/posts_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { PostReactionType } from '#enums/post'
import PostReaction from '#models/post_reaction'
import { ModelObject } from '@adonisjs/lucid/types/model'
import type { HttpContext } from '@adonisjs/core/http'
import type { UUID } from 'crypto'
import type { UUID } from 'node:crypto'
import { UserService } from '#services/user_service'

export default class PostsService {
Expand Down Expand Up @@ -59,7 +59,7 @@ export default class PostsService {
.where('id', id)
.preload('user')
.preload('reactions')
return !!result ? result[0] : null
return result ? result[0] : null
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/services/user_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { AttachmentModel, AttachmentType } from '#models/attachment'
import User from '#models/user'
import AttachmentService from '#services/attachment_service'
import { HttpContext } from '@adonisjs/core/http'
import { UUID } from 'crypto'
import { UUID } from 'node:crypto'

export class UserService {
private readonly attachmentService: AttachmentService
Expand Down
2 changes: 1 addition & 1 deletion database/factories/post_report_factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PostReport from '#models/post_report'
import { PostReportReason } from '#enums/post'
import { UserFactory } from '#database/factories/user_factory'
import { PostFactory } from '#database/factories/post_factory'
import { randomUUID } from 'crypto'
import { randomUUID } from 'node:crypto'

export const PostReportFactory = factory
.define(PostReport, async ({ faker }) => {
Expand Down
2 changes: 1 addition & 1 deletion inertia/components/posts/delete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
DialogTitle,
DialogTrigger,
} from '@/components/ui/dialog'
import { useToast } from '@/components/ui/use-toast'
import { useToast } from '@/components/ui/use_toast'
import { ModelObject } from '@adonisjs/lucid/types/model'
import { router } from '@inertiajs/react'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useEffect, useMemo, useState } from 'react'
import { router } from '@inertiajs/react'
import { useToast } from '@/components/ui/use-toast'
import PostCard from '@/components/posts/post-card'
import { useIntersectionObserver } from '@/hooks/use-intersection-observer'
import { useToast } from '@/components/ui/use_toast'
import PostCard from '@/components/posts/post_card'
import { useIntersectionObserver } from '@/hooks/use_intersection_observer'
import { PostResponse } from '#interfaces/post'
import { UserResponse } from '#interfaces/user'
import { Loader2 } from 'lucide-react'
Expand Down
6 changes: 3 additions & 3 deletions inertia/components/posts/form.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React, { useEffect, useMemo, useRef } from 'react'
import { MAX_POST_CONTENT_SIZE, MIN_POST_CONTENT_SIZE } from '#validators/post'
import FileUploadPreview from '@/components/generic/file-upload-preview'
import FileUploadPreview from '@/components/generic/file_upload_preview'
import { Button } from '@/components/ui/button'
import { Label } from '@/components/ui/label'
import { Textarea } from '@/components/ui/textarea'
import { useToast } from '@/components/ui/use-toast'
import { useToast } from '@/components/ui/use_toast'
import { cn } from '@/lib/utils'
import { useForm, usePage } from '@inertiajs/react'
import { Paperclip } from 'lucide-react'
Expand Down Expand Up @@ -45,7 +45,7 @@ export default function Form({

const uploadImages = useRef<HTMLInputElement | null>(null)

const method = !!post ? 'patch' : 'post'
const method = post ? 'patch' : 'post'

function addFiles(e: React.ChangeEvent<HTMLInputElement>) {
if (!e.target.files) return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ import {
DropdownMenuContent,
DropdownMenuTrigger,
DropdownMenuItem,
} from '@/components/ui/dropdown-menu'
} from '@/components/ui/dropdown_menu'
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar'
import { UpdatePost } from '@/components/posts/update'
import { DeletePost } from '@/components/posts/delete'
import { PostResponse } from 'app/interfaces/post'
import { AttachmentResponse } from 'app/interfaces/attachment'
import { formatDistanceToNow } from 'date-fns'
import { PostReactionType } from '#enums/post'
import { HoverCard, HoverCardContent, HoverCardTrigger } from '@/components/ui/hover-card'
import type { UUID } from 'crypto'
import { HoverCard, HoverCardContent, HoverCardTrigger } from '@/components/ui/hover_card'
import type { UUID } from 'node:crypto'
import { UserResponse } from '#interfaces/user'
import { ReportPost } from '@/components/posts/report'

Expand Down Expand Up @@ -266,24 +266,24 @@ function PostReaction({
}, [reaction.type])

const reactionCounts = useMemo(() => {
const counts = { ...post.reactions.reactionsCounts }
const accCounts = { ...post.reactions.reactionsCounts }
if (reaction.type && post.reactions.reacted) {
counts[reaction.type] = counts[reaction.type] + 1
counts[post.reactions.reacted] = counts[post.reactions.reacted] - 1
accCounts[reaction.type] = accCounts[reaction.type] + 1
accCounts[post.reactions.reacted] = accCounts[post.reactions.reacted] - 1
} else if (reaction.type && !post.reactions.reacted) {
counts[reaction.type] = counts[reaction.type] + 1
accCounts[reaction.type] = accCounts[reaction.type] + 1
} else if (!reaction.type && post.reactions.reacted) {
counts[post.reactions.reacted] = counts[post.reactions.reacted] - 1
accCounts[post.reactions.reacted] = accCounts[post.reactions.reacted] - 1
}
return counts
return accCounts
}, [reaction.type])

return (
<div className="flex flex-row gap-2 items-center">
<HoverCard>
<HoverCardTrigger>
<button
className={`trigger-user-post-react border rounded-full px-2 cursor-pointer ${!!reaction.type ? 'bg-blue-100 border-blue-400 hover:bg-blue-400-200' : 'bg-slate-50 border-slate-400 hover:bg-slate-200'}`}
className={`trigger-user-post-react border rounded-full px-2 cursor-pointer ${reaction.type ? 'bg-blue-100 border-blue-400 hover:bg-blue-400-200' : 'bg-slate-50 border-slate-400 hover:bg-slate-200'}`}
disabled={isSubmitting}
>
{reaction.type ? REACTIONS[reaction.type] : '+'}
Expand Down
18 changes: 9 additions & 9 deletions inertia/components/posts/report.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
DialogTitle,
DialogTrigger,
} from '@/components/ui/dialog'
import { useToast } from '@/components/ui/use-toast'
import { useToast } from '@/components/ui/use_toast'
import { Button } from '@/components/ui/button'
import { Label } from '@/components/ui/label'
import { Textarea } from '@/components/ui/textarea'
Expand Down Expand Up @@ -52,16 +52,16 @@ export function ReportPost({ post, trigger }: { post: PostResponse; trigger: Rea
.then((response) => {
return response.json()
})
.then((data) => {
if (data) {
.then((json) => {
if (json) {
setHasReported({
id: data.id,
reason: data.reason,
description: data.description,
id: json.id,
reason: json.reason,
description: json.description,
})
setData({
reason: data.reason,
description: data.description,
reason: json.reason,
description: json.description,
})
}
})
Expand Down Expand Up @@ -129,7 +129,7 @@ export function ReportPost({ post, trigger }: { post: PostResponse; trigger: Rea
</Label>
<Select
value={data.reason}
onValueChange={(value) => {
onValueChange={(value: string) => {
setData((prevState) => {
return {
...prevState,
Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 328ca63

Please sign in to comment.