-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8775fe5
commit a06eb1f
Showing
4 changed files
with
46 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import Services from '../../services'; | ||
import { BadRequestError } from '../../utils/errorHandler'; | ||
|
||
import type { ILinkForCreate } from '@linx/shared'; | ||
import type { Reply, Request } from '../../types'; | ||
|
||
export default async function create(request: Request, reply: Reply) { | ||
const { shorter_name, url } = request.body as ILinkForCreate; | ||
const user = request.user; | ||
|
||
if (!shorter_name || !url) { | ||
throw new BadRequestError('Please provide all required fields'); | ||
} | ||
|
||
const link = await Services.link.create({ | ||
shorter_name, | ||
url, | ||
user_id: user.id, | ||
}); | ||
|
||
return reply.code(201).send({ message: 'Link created', data: { id: link } }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import create from '../../controllers/Link/create'; | ||
import checkJwt from '../../middlewares/checkJwt'; | ||
|
||
import type { IReply } from '@linx/shared'; | ||
import type { | ||
DoneFuncWithErrOrRes, | ||
FastifyInstance, | ||
RegisterOptions, | ||
} from 'fastify'; | ||
|
||
export default function link( | ||
fastify: FastifyInstance, | ||
_: RegisterOptions, | ||
done: DoneFuncWithErrOrRes, | ||
) { | ||
fastify.register(checkJwt); | ||
|
||
fastify.post<{ Reply: IReply }>('/create', create); | ||
|
||
done(); | ||
} |