Skip to content

Commit

Permalink
Merge pull request #145 from wizelineacademy/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
william-monroy authored Nov 27, 2023
2 parents 8ed9b46 + 72b2ed2 commit 2f22c5d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ jobs:
run: |
sshpass -p "${{ secrets.LIGHTSAIL_SSH_PASS }}" ssh -o StrictHostKeyChecking=no [email protected] "cd apps/web && pm2 start pnpm --name "web" -- start"
- name: Remove web node_modules
run: |
rm -rf apps/web/node_modules
- name: Create output artifact
uses: actions/upload-artifact@v2
with:
Expand Down Expand Up @@ -218,6 +222,10 @@ jobs:
run: |
sshpass -p "${{ secrets.LIGHTSAIL_SSH_PASS }}" ssh -o StrictHostKeyChecking=no [email protected] "cd apps/docs && pm2 start pnpm --name "docs" -- start -- -p 3001"
- name: Remove docs node_modules
run: |
rm -rf apps/docs/node_modules
- name: Create output artifact
uses: actions/upload-artifact@v2
with:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export default function GroupBody(): JSX.Element {
useEffect(() => {
async function getGroupData(): Promise<void> {
try {
console.log("enviroment", process.env);
const response = await fetch(
`http://${
process.env.ENVIROMENT === "production"
Expand Down
41 changes: 23 additions & 18 deletions apps/web/lib/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,25 +419,30 @@ export async function incrementUserCreditsRemaining(idUser: number, creditIncrem
export async function decrementUserCreditsRemaining(idUser: number, creditDecrement: number): Promise<PrismaResponse<User>> {
if (creditDecrement < 0) {
return { status: 400, message: "Invalid credit decrement value given." }
}
}

try {
const user: User = await prisma.user.update({
where: {
id: idUser,
creditsRemaining: {
gte: creditDecrement
}
},
data: {
creditsRemaining: {
decrement: creditDecrement
const getUserResult: PrismaResponse<User> = await getUser(idUser)

if (getUserResult.status === 200 && getUserResult.data){
if (creditDecrement === 0){
return {status: 200, data: getUserResult.data}
}

try {
const updatedUser: User = await prisma.user.update({
where: {
id: idUser
},
data: {
creditsRemaining: Math.max(getUserResult.data.creditsRemaining - creditDecrement, 0)
}
}
})
})

return { status: 200, data: user }
} catch (error: any) {
return { status: 500, message: error.message }
}
return {status: 200, data: updatedUser}
} catch (error: any) {
return {status: 500, message: error.message}
}
}

return {status: getUserResult.status, message: getUserResult.message ?? "Failed to updated the user's credit number"}
}

0 comments on commit 2f22c5d

Please sign in to comment.