-
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.
* Answer insert function * Comments added * Merge conflict push 11/12/23 Tags changes * Tags Changes * Tags filter * list view create update delete for Events * About cms update * Abou Gallery add image
- Loading branch information
Showing
7 changed files
with
68 additions
and
4 deletions.
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
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 |
---|---|---|
@@ -1,10 +1,37 @@ | ||
import HttpError from '../../utils/HttpError' | ||
import { UpdateAbout } from '../../types/DBTypes' | ||
import { AddImage, UpdateAbout } from '../../types/DBTypes' | ||
import * as Service from './AboutService' | ||
import fs from 'fs' | ||
import { readFileAsStream } from '../../utils/file' | ||
import { | ||
deleteFile, | ||
getObjectUrl, | ||
uploadFile, | ||
} from '../AWS-Bucket/UploadService' | ||
import dbErrorHandler from '../../utils/dbErrorHandler' | ||
import { object } from 'zod' | ||
|
||
export async function updateAbout(body: UpdateAbout) { | ||
const update = await Service.updateAboutPage(body) | ||
|
||
if (!update) throw new HttpError('Missing or not found, Check syntax', 400) | ||
return update | ||
} | ||
|
||
export async function addImage(body: AddImage, image: Express.Multer.File) { | ||
try { | ||
const fileKey = image.filename | ||
const stream: fs.ReadStream = await readFileAsStream(image.path) | ||
await uploadFile(stream, fileKey, image.mimetype) | ||
const data = { ...body, imagesrc: image.filename } | ||
const addImage = await Service.addImage(data) | ||
|
||
deleteFile(image.filename) | ||
|
||
if (!addImage) throw new HttpError('Failed: Empty or not found', 400) | ||
return { ...addImage, imagesrc: getObjectUrl(fileKey) } | ||
} catch (error) { | ||
deleteFile(image.filename) | ||
dbErrorHandler(error) | ||
} | ||
} |
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 |
---|---|---|
@@ -1,7 +1,13 @@ | ||
import * as AboutController from './AboutController' | ||
import express from 'express' | ||
import { UserGuard } from '../AuthGuard/UserGuard' | ||
import upload from '../../config/multer' | ||
|
||
export const AboutRouter = express.Router() | ||
|
||
AboutRouter.put('/', AboutController.updateAbout) | ||
AboutRouter.post( | ||
'/about_gallery', | ||
upload.single('imagesrc'), | ||
AboutController.addImage | ||
) |
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 |
---|---|---|
@@ -1,11 +1,18 @@ | ||
import { UpdateAbout } from '../../types/DBTypes' | ||
import { AddImage, Gallery, UpdateAbout } from '../../types/DBTypes' | ||
import { db } from '../../config/database' | ||
|
||
export async function updateAboutPage(update: UpdateAbout) { | ||
console.log(update) | ||
return await db | ||
.updateTable('about_cms') | ||
.set(update) | ||
.returningAll() | ||
.executeTakeFirst() | ||
} | ||
|
||
export async function addImage(addImage: Gallery): Promise<Gallery> { | ||
return await db | ||
.insertInto('about_gallery') | ||
.values(addImage) | ||
.returningAll() | ||
.executeTakeFirst() | ||
} |
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