Skip to content

Commit

Permalink
send
Browse files Browse the repository at this point in the history
  • Loading branch information
talafarael committed Apr 2, 2024
1 parent 7c78dc7 commit 1437898
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"workbench.statusBar.visible": true
}
51 changes: 40 additions & 11 deletions src/Router/authAuction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,20 @@ const User = require("../model/user")
const verifyToken = require("../middleware/verify")
import express, {Request, Response} from "express"
import {uploadFile, getFileStream} from "../s3"
const AuctionDelete = require("../model/Delet")
const checkUserOwner = require("../middleware/checkUserOwner")
const {Storage} = require("@google-cloud/storage")
const verifyTime = require("../middleware/timeMiddleware")
const projectId = "commanding-ring-409619" // Get this from Google Cloud
const keyFilename = "mykey.json"
const generateAccessToken=require('../middleware/generateAccessToken')
const passwordSendDelete=require('../passwordSendDelete')
const bcrypt = require("bcryptjs")

const generateAccessToken = require("../middleware/generateAccessToken")
const PasswordSendDelete = require("../passwordSendDelete")
// const fs = require("fs")
// const util = require("util")
// const unlinkFile = util.promisify(fs.unlink)

const passwordSendDelete = new PasswordSendDelete()
// const storage = new Storage({
// projectId,
// keyFilename,
Expand Down Expand Up @@ -323,18 +326,44 @@ class authAuction {
res.status(400).json({message: "Registration error"})
}
}
async deleteAuctionOne(req: Request, res: Response) {
async deleteAuctionSend(req: Request, res: Response) {
try {
const {token, _id} = req.body
const {user, id} = await verifyToken(token, res)
const {checkOwner}=checkUserOwner(res,user,_id)
const passwordUser = Math.floor(Math.random() * 8999) + 1000
await passwordSendDelete.sendmessage({
emailUser: user.email,
password: passwordUser.toString(),
})
generateAccessToken(passwordUser)
const {checkOwner} = await checkUserOwner({res, user, _id})
const passwordUser: number = Math.floor(Math.random() * 8999) + 1000
const hashPassword = await bcrypt.hash(passwordUser.toString(), 7)
await AuctionDelete.deleteOne({id: _id})


await passwordSendDelete.sendmessage({
emailUser: user.email,
password: passwordUser.toString(),
})

const deleteAuction = new AuctionDelete({
idUser: id,
id: _id,
password: hashPassword,
})
deleteAuction.save()
res.status(200).json({
message: "",
})
} catch (e) {
console.log(e)
res.status(400).json({message: "Registration error"})
}
}
async deleteAuction(req: Request, res: Response) {
try {
const {token, _id} = req.body
const {user, id} = await verifyToken(token, res)
const {checkOwner} = await checkUserOwner({res, user, _id})
const deleteAuction=AuctionDelete.find
res.status(200).json({
message: "",
})
} catch (e) {
console.log(e)
res.status(400).json({message: "Registration error"})
Expand Down
2 changes: 1 addition & 1 deletion src/authRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ router.post('/createauction',type,auctionController.createAuction)
router.post('/getauctioninfoforchange',auctionController.getInfoForChange)
router.post('/editfieldauction',middlewareUser,auctionController.changeInfoForChange)


router.post('/deleteauctionsend',middlewareUser,auctionController.deleteAuctionSend)

module.exports = router
2 changes: 2 additions & 0 deletions src/middleware/checkUserOwner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const checkOwner = Owner.find((auction: string) => auction == _id)
if (!checkOwner) {
return res.status(400).json({message: "You are not owner"})
}
console.log('aaaa')
console.log( checkOwner)
return checkOwner
} catch (error) {
return res.status(401).json({
Expand Down
3 changes: 2 additions & 1 deletion src/model/Delet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ const {model, Schema} = require("mongoose")
const AuctionDelete = new Schema({
id:{type:String},
password:{type:String}
})
}, { timestamps: true })
AuctionDelete.index( { "createdAt": 1 }, { expireAfterSeconds: 420 } );
module.exports = model("AuctionDelete",AuctionDelete)

0 comments on commit 1437898

Please sign in to comment.