Skip to content

Commit

Permalink
easy
Browse files Browse the repository at this point in the history
  • Loading branch information
0-don committed Feb 26, 2024
1 parent e7ba262 commit 2a74907
Show file tree
Hide file tree
Showing 27 changed files with 175 additions and 172 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- CreateEnum
CREATE TYPE "UserRoleName" AS ENUM ('ADMIN', 'MOD', 'USER', 'GUEST');
CREATE TYPE "UserRoleName" AS ENUM ('Admin', 'Mod', 'User', 'Guest');

-- CreateEnum
CREATE TYPE "Unit" AS ENUM ('G', 'L', 'ML', 'KG');
Expand Down
8 changes: 4 additions & 4 deletions server/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -591,10 +591,10 @@ model WeeklyMealGroup {
}

enum UserRoleName {
ADMIN
MOD
USER
GUEST
Admin
Mod
User
Guest
}

enum Unit {
Expand Down
6 changes: 3 additions & 3 deletions server/prisma/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const seed = async () => {
await createUser({
email: EMAIL,
password: await argon2.hash("!admin"),
roles: ["USER", "ADMIN"],
roles: ["User", "Admin"],
});

await seedSettings();
Expand Down Expand Up @@ -127,7 +127,7 @@ const seedUsers = async () => {
const user = await createUser({
email: faker.internet.email(),
password: await argon2.hash("test"),
roles: ["USER"],
roles: ["User"],
});
await mealLocationsAndAllergens(user.id);
}
Expand Down Expand Up @@ -715,7 +715,7 @@ const seedWeeklyMealGroups = async () => {
for (const mealBoardPlan of mealBoardPlans) {
for (let year = startYear; year <= currentYear; year++) {
// For past years use all weeks, for the current year only up to the current week
let lastWeek = year < currentYear ? 52 : currentWeekNumber;
const lastWeek = year < currentYear ? 52 : currentWeekNumber;

for (let week = 1; week <= lastWeek; week++) {
for (let groupIndex = 0; groupIndex < 3; groupIndex++) {
Expand Down
8 changes: 4 additions & 4 deletions server/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -429,10 +429,10 @@ type UserRole {
}

enum UserRoleName {
ADMIN
MOD
USER
GUEST
Admin
Mod
User
Guest
}

type Settings {
Expand Down
4 changes: 2 additions & 2 deletions server/src/app_modules/guards/roles.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class RolesGuard implements CanActivate {

if (!rules.length) throw new UnauthorizedException(["enpoint has no role"]);

if (rules.includes("GUEST")) return true;
if (rules.includes("Guest")) return true;

const ctx = GqlExecutionContext.create(context).getContext();

Expand All @@ -44,7 +44,7 @@ export class RolesGuard implements CanActivate {
}) as JwtUser;
await this.prisma.token.findFirstOrThrow({ where: { token } });

if (user.roles.includes("ADMIN")) return true;
if (user.roles.includes("Admin")) return true;

return rules.some((rule) => user.roles.includes(rule));
} catch (_) {
Expand Down
7 changes: 2 additions & 5 deletions server/src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ export class AuthService {
});

try {
if (
user &&
(await argon2.verify(user.password, data.password))
) {
if (user && (await argon2.verify(user.password, data.password))) {
const { password, ...result } = user;
return result as User & {
userRole: UserRole[];
Expand Down Expand Up @@ -66,7 +63,7 @@ export class AuthService {
await this.prisma.userRole.create({
data: {
userId: user.id,
name: "USER",
name: "User",
createdBy: user.id,
updatedBy: user.id,
},
Expand Down
6 changes: 3 additions & 3 deletions server/src/auth/resolver/auth-user.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ export class AuthUserResolver {
) {}

@Mutation(() => Boolean, { nullable: true })
@Roles("USER", "MOD")
@Roles("User", "Mod")
async logout(@Context() ctx: GraphQLContext, @CurrentUser() me?: JwtUser) {
if (!me) return null;

return await this.authService.logout(ctx);
}

@Mutation(() => Boolean, { nullable: true })
@Roles("USER", "MOD")
@Roles("User", "Mod")
async changePasswordUser(
@Args("password") password: string,
@Args("newPassword") newPassword: string,
Expand All @@ -42,7 +42,7 @@ export class AuthUserResolver {
}

@Mutation(() => Boolean)
@Roles("USER", "MOD")
@Roles("User", "Mod")
async deleteAccountTokensUser(
@Context() ctx: GraphQLContext,
@CurrentUser() me?: JwtUser,
Expand Down
6 changes: 3 additions & 3 deletions server/src/auth/resolver/auth.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class AuthResolver {
) {}

@Query(() => User, { nullable: true })
@Roles("USER", "MOD")
@Roles("User", "Mod")
async me(@CurrentUser() me?: JwtUser) {
if (!me) return null;

Expand Down Expand Up @@ -58,7 +58,7 @@ export class AuthResolver {
}

@Mutation(() => User, { nullable: true })
@Roles("GUEST")
@Roles("Guest")
async registerUser(
@Args("data") data: RegisterUserInput,
@Context() ctx: GraphQLContext,
Expand All @@ -82,7 +82,7 @@ export class AuthResolver {
}

@Mutation(() => User, { nullable: true })
@Roles("GUEST")
@Roles("Guest")
async loginUser(
@Args("data") data: LoginUserInput,
@Context() ctx: GraphQLContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class AllergensUserResolver {
) {}

@Query(() => [Allergens], { nullable: true })
@Roles("USER", "MOD")
@Roles("User", "Mod")
async getAllAllergensUser(
@Args() args: FindManyAllergensArgs,
@Info() info: GraphQLResolveInfo,
Expand Down
18 changes: 9 additions & 9 deletions server/src/ingredient/resolver/ingredient-admin.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class IngredientAdminResolver {
) {}

@Query(() => [Ingredient], { nullable: true })
@Roles("ADMIN")
@Roles("Admin")
async getAllIngredientsAdmin(
@Args() args: FindManyIngredientArgs,
@Info() info: GraphQLResolveInfo,
Expand All @@ -41,7 +41,7 @@ export class IngredientAdminResolver {
}

@Query(() => Ingredient, { nullable: true })
@Roles("ADMIN")
@Roles("Admin")
async getIngredientAdmin(
@Args() args: FindFirstIngredientArgs,
@Info() info: GraphQLResolveInfo,
Expand All @@ -57,7 +57,7 @@ export class IngredientAdminResolver {
}

@Mutation(() => Ingredient, { nullable: true })
@Roles("ADMIN")
@Roles("Admin")
async createIngredientAdmin(
@Args() args: CreateOneIngredientArgs,
@Info() info: GraphQLResolveInfo,
Expand All @@ -73,7 +73,7 @@ export class IngredientAdminResolver {
}

@Mutation(() => [Ingredient], { nullable: true })
@Roles("ADMIN")
@Roles("Admin")
async createManyIngredientsAdmin(
@Args() args: CreateManyIngredientArgs,
@Info() info: GraphQLResolveInfo,
Expand All @@ -92,7 +92,7 @@ export class IngredientAdminResolver {
}

@Mutation(() => Ingredient, { nullable: true })
@Roles("ADMIN")
@Roles("Admin")
async deleteIngredientAdmin(
@Args() args: DeleteOneIngredientArgs,
@Info() info: GraphQLResolveInfo,
Expand All @@ -108,7 +108,7 @@ export class IngredientAdminResolver {
}

@Mutation(() => Int, { nullable: true })
@Roles("ADMIN")
@Roles("Admin")
async deleteManyIngredientsAdmin(@Args() args: DeleteManyIngredientArgs) {
try {
return (await this.prisma.ingredient.deleteMany({ ...args })).count;
Expand All @@ -119,7 +119,7 @@ export class IngredientAdminResolver {
}

@Mutation(() => Ingredient, { nullable: true })
@Roles("ADMIN")
@Roles("Admin")
async updateIngredientAdmin(
@Args() args: UpdateOneIngredientArgs,
@Info() info: GraphQLResolveInfo,
Expand All @@ -135,7 +135,7 @@ export class IngredientAdminResolver {
}

@Mutation(() => [Ingredient], { nullable: true })
@Roles("ADMIN")
@Roles("Admin")
async updateManyIngredientsAdmin(
@Args() args: UpdateManyIngredientArgs,
@Info() info: GraphQLResolveInfo,
Expand Down Expand Up @@ -163,7 +163,7 @@ export class IngredientAdminResolver {
}

@Mutation(() => Ingredient, { nullable: true })
@Roles("ADMIN")
@Roles("Admin")
async upsertIngredientAdmin(
@Args() args: UpsertOneIngredientArgs,
@Info() info: GraphQLResolveInfo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class MealBoardPlanAdminResolver {
) {}

@Query(() => [MealBoardPlan], { nullable: true })
@Roles("ADMIN")
@Roles("Admin")
async getAllMealBoardPlansAdmin(
@Args() args: FindManyMealBoardPlanArgs,
@Info() info: GraphQLResolveInfo,
Expand All @@ -42,7 +42,7 @@ export class MealBoardPlanAdminResolver {
}

@Query(() => MealBoardPlan, { nullable: true })
@Roles("ADMIN")
@Roles("Admin")
async getMealBoardPlanAdmin(
@Args() args: FindFirstMealBoardPlanArgs,
@Info() info: GraphQLResolveInfo,
Expand All @@ -58,7 +58,7 @@ export class MealBoardPlanAdminResolver {
}

@Mutation(() => MealBoardPlan, { nullable: true })
@Roles("ADMIN")
@Roles("Admin")
async createMealBoardPlanAdmin(
@Args() args: CreateOneMealBoardPlanArgs,
@Info() info: GraphQLResolveInfo,
Expand All @@ -77,7 +77,7 @@ export class MealBoardPlanAdminResolver {
}

@Mutation(() => [MealBoardPlan], { nullable: true })
@Roles("ADMIN")
@Roles("Admin")
async createManyMealBoardPlansAdmin(
@Args() args: CreateManyMealBoardPlanArgs,
@Info() info: GraphQLResolveInfo,
Expand All @@ -101,7 +101,7 @@ export class MealBoardPlanAdminResolver {
}

@Mutation(() => MealBoardPlan, { nullable: true })
@Roles("ADMIN")
@Roles("Admin")
async deleteMealBoardPlanAdmin(
@Args() args: DeleteOneMealBoardPlanArgs,
@Info() info: GraphQLResolveInfo,
Expand All @@ -117,7 +117,7 @@ export class MealBoardPlanAdminResolver {
}

@Mutation(() => Int, { nullable: true })
@Roles("ADMIN")
@Roles("Admin")
async deleteManyMealBoardPlansAdmin(
@Args() args: DeleteManyMealBoardPlanArgs,
) {
Expand All @@ -130,7 +130,7 @@ export class MealBoardPlanAdminResolver {
}

@Mutation(() => MealBoardPlan, { nullable: true })
@Roles("ADMIN")
@Roles("Admin")
async updateMealBoardPlanAdmin(
@Args("data") data: MealBoardPlanUncheckedUpdateInput,
@Args({ name: "where", type: () => WeeklyMealGroupWhereUniqueInput })
Expand All @@ -152,7 +152,7 @@ export class MealBoardPlanAdminResolver {
}

@Mutation(() => [MealBoardPlan], { nullable: true })
@Roles("ADMIN")
@Roles("Admin")
async updateManyMealBoardPlansAdmin(
@Args() args: UpdateManyMealBoardPlanArgs,
@Info() info: GraphQLResolveInfo,
Expand Down Expand Up @@ -182,7 +182,7 @@ export class MealBoardPlanAdminResolver {
}

@Mutation(() => MealBoardPlan, { nullable: true })
@Roles("ADMIN")
@Roles("Admin")
async upsertMealBoardPlanAdmin(
@Args() args: UpsertOneMealBoardPlanArgs,
@Info() info: GraphQLResolveInfo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class MealBoardPlanUserResolver {
) {}

@Query(() => [MealBoardPlan], { nullable: true })
@Roles("USER", "MOD", "ADMIN")
@Roles("User", "Mod", "Admin")
async getAllMealBoardPlansUser(
@Args() args: FindManyMealBoardPlanArgs,
@Info() info: GraphQLResolveInfo,
Expand Down
Loading

0 comments on commit 2a74907

Please sign in to comment.