Changes
This commit is contained in:
@@ -20,27 +20,27 @@ app.get("/", async (req,res) => {
|
||||
app.post("/executeTimeCommand", async (req,res) => {
|
||||
console.log(req.body)
|
||||
let body = req.body
|
||||
let deviceData = (await supabase.from("devices").select().eq("id",body.id).single()).data
|
||||
let deviceData = (await supabase.from("devices").select().eq("id",body.deviceId).single()).data
|
||||
let currentTenant = deviceData.tenant
|
||||
console.log(deviceData)
|
||||
console.log(currentTenant)
|
||||
|
||||
|
||||
if(deviceData.password === body.password) {
|
||||
let userId = ""
|
||||
if(deviceData.password === body.devicePassword) {
|
||||
let user = {}
|
||||
if(!body.tokenId && !body.userId) {
|
||||
res.sendStatus(400)
|
||||
}
|
||||
else if(body.tokenId && !body.userId) {
|
||||
userId = ((await supabase.from("profiles").select().eq("tokenId",body.tokenId).single()).data).id
|
||||
console.log(userId)
|
||||
user = ((await supabase.from("profiles").select().eq("tokenId",body.tokenId).single()).data)
|
||||
console.log(user)
|
||||
} else {
|
||||
userId = body.userId
|
||||
user.id = body.userId
|
||||
}
|
||||
|
||||
|
||||
|
||||
let startedWorkingTime = (await supabase.from("workingtimes").select().eq("user",userId).is("end",null).single()).data
|
||||
let startedWorkingTime = (await supabase.from("workingtimes").select().eq("user",user.id).is("end",null).single()).data
|
||||
|
||||
if(startedWorkingTime) {
|
||||
//Stop Time
|
||||
@@ -55,7 +55,7 @@ app.post("/executeTimeCommand", async (req,res) => {
|
||||
console.log("Time Stopped")
|
||||
|
||||
res.json({
|
||||
message: "Zeit gestoppt",
|
||||
message: `Deine Zeit wurde gestoppt, bis bald ${user.firstName}`,
|
||||
type: "stopped"
|
||||
})
|
||||
|
||||
@@ -65,7 +65,7 @@ app.post("/executeTimeCommand", async (req,res) => {
|
||||
|
||||
const {data,error} = await supabase.from("workingtimes")
|
||||
.insert([{
|
||||
user: userId,
|
||||
user: user.id,
|
||||
date: dayjs().format("YYYY-MM-DD"),
|
||||
start: String(dayjs().format("HH:mm:ss"))+ "+01",
|
||||
tenant: currentTenant,
|
||||
@@ -78,7 +78,7 @@ app.post("/executeTimeCommand", async (req,res) => {
|
||||
console.log("Time Started")
|
||||
|
||||
res.json({
|
||||
message: "Zeit gestartet",
|
||||
message: `Hallo ${user.firstName}, deine Zeit wurde gestartet`,
|
||||
type: "started"
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user