Skip to content

Commit

Permalink
fix: just formatted the code
Browse files Browse the repository at this point in the history
  • Loading branch information
Drixares committed Nov 2, 2024
1 parent bc0107d commit b272994
Show file tree
Hide file tree
Showing 12 changed files with 1,222 additions and 1,265 deletions.
178 changes: 88 additions & 90 deletions controllers/challenges.ts
Original file line number Diff line number Diff line change
@@ -1,90 +1,88 @@
import DB from "@/database/config";
import { challenges } from "@/database/schema/challenges";
import { eq } from "drizzle-orm";

export default abstract class ChallengesController {

public static async getAllChallengesWithDetails() {
const allChallenges = await DB.instance
.select({
id: challenges.id,
name: challenges.name,
score: challenges.score,
clubId: challenges.clubId,
})
.from(challenges)

return allChallenges;
}

public static async getChallenge(id: number) {
const challenge = await DB.instance
.select({
id: challenges.id,
name: challenges.name,
score: challenges.score,
})
.from(challenges)
.where(eq(challenges.id, id))
.limit(1);

return challenge.length ? challenge[0] : null;
}

public static async getChallengeWithDetails(id: number) {
const challenge = await DB.instance
.select({
id: challenges.id,
name: challenges.name,
score: challenges.score,
clubId: challenges.clubId,
})
.from(challenges)
.where(eq(challenges.id, id));

return challenge.length ? challenge[0] : null;
}


public static async createChallenge(clubId: number, score: number, name: string) {
const challenge = await DB.instance
.insert(challenges)
.values({
clubId,
score,
name,
})
.returning({
id: challenges.id,
name: challenges.name,
score: challenges.score,
clubId: challenges.clubId,
});

return challenge.length ? challenge[0] : null;
}

public static async updateChallenge(id: number, score?: number, name?: string) {
const challenge = await DB.instance
.update(challenges)
.set({
score,
name,
})
.where(eq(challenges.id, id))
.returning({
id: challenges.id,
name: challenges.name,
score: challenges.score,
clubId: challenges.clubId,
});

return challenge.length ? challenge[0] : null;
}

public static async deleteChallenge(id: number) {
await DB.instance.delete(challenges).where(eq(challenges.id, id));
}

public static async getDailyChallenges() {}
}
import DB from "@/database/config";
import { challenges } from "@/database/schema/challenges";
import { eq } from "drizzle-orm";

export default abstract class ChallengesController {
public static async getAllChallengesWithDetails() {
const allChallenges = await DB.instance
.select({
id: challenges.id,
name: challenges.name,
score: challenges.score,
clubId: challenges.clubId
})
.from(challenges);

return allChallenges;
}

public static async getChallenge(id: number) {
const challenge = await DB.instance
.select({
id: challenges.id,
name: challenges.name,
score: challenges.score
})
.from(challenges)
.where(eq(challenges.id, id))
.limit(1);

return challenge.length ? challenge[0] : null;
}

public static async getChallengeWithDetails(id: number) {
const challenge = await DB.instance
.select({
id: challenges.id,
name: challenges.name,
score: challenges.score,
clubId: challenges.clubId
})
.from(challenges)
.where(eq(challenges.id, id));

return challenge.length ? challenge[0] : null;
}

public static async createChallenge(clubId: number, score: number, name: string) {
const challenge = await DB.instance
.insert(challenges)
.values({
clubId,
score,
name
})
.returning({
id: challenges.id,
name: challenges.name,
score: challenges.score,
clubId: challenges.clubId
});

return challenge.length ? challenge[0] : null;
}

public static async updateChallenge(id: number, score?: number, name?: string) {
const challenge = await DB.instance
.update(challenges)
.set({
score,
name
})
.where(eq(challenges.id, id))
.returning({
id: challenges.id,
name: challenges.name,
score: challenges.score,
clubId: challenges.clubId
});

return challenge.length ? challenge[0] : null;
}

public static async deleteChallenge(id: number) {
await DB.instance.delete(challenges).where(eq(challenges.id, id));
}

public static async getDailyChallenges() {}
}
Loading

0 comments on commit b272994

Please sign in to comment.