Skip to content

Commit 8a33968

Browse files
committed
Rename GroupKind to GroupType
1 parent d573f3b commit 8a33968

10 files changed

+39
-36
lines changed

migrations/20210825151547_add_group_kind_to_groups.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import * as Knex from 'knex'
22

33
export async function up(knex: Knex): Promise<void> {
44
return knex.schema.alterTable('groups', table => {
5-
table.enu('kind', ['CLASSIC', 'PRIVATE'], {
5+
table.enu('type', ['CLASSIC', 'PRIVATE'], {
66
useNative: true,
7-
enumName: 'group_kind'
7+
enumName: 'group_type'
88
}).defaultTo('CLASSIC')
99
})
1010
}
1111

1212
export async function down(knex: Knex): Promise<void> {
1313
return knex.schema.alterTable('groups', table => {
14-
table.dropColumn('kind')
14+
table.dropColumn('type')
1515
})
1616
}

seeds/02_add_groups.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export async function seed(knex: Knex): Promise<void> {
3939
maxAttendees: 100,
4040
createdAt: new Date(),
4141
ownerId,
42-
kind: (i + j) % 3 === 0 ? 'CLASSIC' : 'PRIVATE'
42+
type: (i + j) % 3 === 0 ? 'CLASSIC' : 'PRIVATE'
4343
}
4444
console.log('\x1b[33m%s\x1b[0m',
4545
`Group: #${groupId} ${group.name}, floor: ${group.room}, owner: ${ownerId}`)
@@ -56,7 +56,7 @@ export async function seed(knex: Knex): Promise<void> {
5656
connectCountSum++
5757

5858
for (let k = 1; k < ownerId; ++k) {
59-
const isUnapproved = group.kind === 'PRIVATE' && (k % 2 === 0 || k % 3 === 0)
59+
const isUnapproved = group.type === 'PRIVATE' && (k % 2 === 0 || k % 3 === 0)
6060
const connect = {
6161
userId: k,
6262
groupId,

src/components/groups/group.middlewares.ts

+12-9
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import winston from 'winston'
77
import { differenceInMinutes } from 'date-fns'
88

99
import { RoleType, User } from '../users/user'
10-
import { Group, GroupKind } from './group'
10+
import { Group, GroupType } from './group'
1111
import { asyncWrapper } from '../../util/asyncWrapper'
1212
import sendMessage from '../../util/sendMessage'
1313
import { sendEmail } from '../../util/sendEmail'
@@ -32,7 +32,7 @@ export const joinGroup = asyncWrapper(async (req: Request, res: Response, next:
3232
} else if (group.endDate < new Date()) {
3333
sendMessage(res, 'Ez a csoport már véget ért!')
3434
} else {
35-
role = group.kind === GroupKind.private ? GroupRole.unapproved : GroupRole.member
35+
role = group.type === GroupType.private ? GroupRole.unapproved : GroupRole.member
3636
}
3737

3838
if (role !== null) {
@@ -54,21 +54,21 @@ export const sendEmailToOwner = asyncWrapper(
5454
const group = req.group
5555

5656
const emailRecepient = await User.query().findOne({ id: group.ownerId })
57-
const emails: Record<GroupKind, Email> = {
58-
[GroupKind.classic]: {
57+
const emails: Record<GroupType, Email> = {
58+
[GroupType.classic]: {
5959
subject: 'Csatlakoztak egy csoportodba!',
6060
body: `${user.name} csatlakozott a(z) ${group.name} csoportodba!`,
6161
link: `/groups/${group.id}`,
6262
linkTitle: 'Csoport megtekintése'
6363
},
64-
[GroupKind.private]: {
64+
[GroupType.private]: {
6565
subject: 'Csatlakoznának egy csoportodba!',
6666
body: `${user.name} csatlakozna a(z) ${group.name} csoportodba!`,
6767
link: `/groups/${group.id}`,
6868
linkTitle: 'Csoport megtekintése'
6969
}
7070
}
71-
sendEmail([emailRecepient], emails[group.kind])
71+
sendEmail([emailRecepient], emails[group.type])
7272
next()
7373
})
7474
export const leaveGroup = asyncWrapper(async (req: Request, res: Response, next: NextFunction) => {
@@ -256,12 +256,15 @@ export const validateGroup = (): ValidationChain[] => {
256256
check('maxAttendees', 'Legalább 1, maximum 100 fő vehet részt!')
257257
.optional({ checkFalsy: true })
258258
.isInt({ min: 1, max: 100 }),
259-
check('kind', 'A csoport típusa')
259+
check('groupType', 'Hibás a csoport típusa')
260+
.custom(x => { console.log(x); return true })
260261
.isString()
261262
.trim()
262-
.default(GroupKind.classic)
263+
.optional()
264+
.default(GroupType.classic)
263265
.toUpperCase()
264-
.isIn(Object.values(GroupKind))
266+
.isIn(Object.values(GroupType))
267+
.withMessage(x => `${x}`)
265268
]
266269
}
267270

src/components/groups/group.routes.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {
2727
} from './group.middlewares'
2828
import { createGroup, getGroup, getGroups, updateGroup, removeGroup } from './group.service'
2929
import { GroupRole } from './grouprole'
30-
import { GroupKind } from './group'
30+
import { GroupType } from './group'
3131

3232
const router = Router()
3333

@@ -50,7 +50,7 @@ router.get('/new', isAuthenticated, (req, res) =>
5050
start: (req.query?.start as string)?.split(' ')[0].slice(0, -3),
5151
end: (req.query?.end as string)?.split(' ')[0].slice(0, -3),
5252
roomId: req.query?.roomId,
53-
GroupKind,
53+
GroupType,
5454
ROOMS
5555
})
5656
)
@@ -89,7 +89,7 @@ router.get('/:id',
8989
isAdmin,
9090
canSeeMembers,
9191
canModerate,
92-
GroupKind,
92+
GroupType,
9393
GroupRole,
9494
userId,
9595
userRole: group.users.find(x => x.id === userId)?.groupRole
@@ -151,8 +151,8 @@ router.get('/:id/copy',
151151
name: req.group.name,
152152
description: req.group.description,
153153
tags: req.group.tags,
154-
kind: req.group.kind,
155-
GroupKind,
154+
type: req.group.type,
155+
GroupType,
156156
ROOMS
157157
})
158158
)
@@ -177,8 +177,8 @@ router.get('/:id/edit',
177177
isEditing: true,
178178
groupId: req.group.id,
179179
maxAttendees: req.group.maxAttendees,
180-
kind: req.group.kind,
181-
GroupKind
180+
type: req.group.type,
181+
GroupType
182182
})
183183
)
184184

src/components/groups/group.service.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Request, Response, NextFunction } from 'express'
22

3-
import { Group, GroupKind } from './group'
3+
import { Group, GroupType } from './group'
44
import { User } from '../users/user'
55
import { formatMdToSafeHTML } from '../../util/convertMarkdown'
66
import { asyncWrapper } from '../../util/asyncWrapper'
@@ -54,7 +54,7 @@ export const createGroup = asyncWrapper(async (req: Request, res: Response, next
5454
endDate: new Date(req.body.endDate),
5555
ownerId: (req.user as User).id,
5656
maxAttendees: parseInt(req.body.maxAttendees) || 100,
57-
kind: req.body.kind as GroupKind
57+
type: req.body.groupType as GroupType
5858
}
5959
)
6060

@@ -75,7 +75,7 @@ export const updateGroup = asyncWrapper(async (req: Request, res: Response, next
7575
startDate: new Date(req.body.startDate),
7676
endDate: new Date(req.body.endDate),
7777
maxAttendees: parseInt(req.body.maxAttendees) || 100,
78-
kind: req.body.kind
78+
type: req.body.groupType
7979
})
8080
.findById(req.params.id)
8181
.catch((err) => {

src/components/groups/group.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { User } from '../users/user'
44
import { GroupMember } from './groupMember'
55
import { GroupRole } from './grouprole'
66

7-
export enum GroupKind {
7+
export enum GroupType {
88
classic = 'CLASSIC',
99
private = 'PRIVATE'
1010
}
@@ -24,7 +24,7 @@ export class Group extends Model {
2424
users: GroupMember[]
2525
createdAt: Date
2626
maxAttendees: number
27-
kind = GroupKind.classic
27+
type = GroupType.classic
2828

2929
isApproved(userId: User['id']): boolean {
3030
return this.users.some(
@@ -33,7 +33,7 @@ export class Group extends Model {
3333

3434

3535
canSeeMembers(userId: User['id']): boolean {
36-
return this.kind !== GroupKind.private || this.isApproved(userId)
36+
return this.type !== GroupType.private || this.isApproved(userId)
3737
}
3838

3939
$beforeInsert(): void {
@@ -83,7 +83,7 @@ export class Group extends Model {
8383
startDate: { type: 'datetime' },
8484
endDate: { type: 'datetime' },
8585
maxAttendees: { type: 'integer' },
86-
kind: { type: 'string' }
86+
type: { type: 'string' }
8787
}
8888
}
8989
}

src/components/users/user.routes.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ import { handleValidationError, checkIdParam } from '../../util/validators'
77
import { RoleType, User } from './user'
88
import { isSameUser } from './user.middlewares'
99
import { getUser, updateRole, updateUser } from './user.service'
10-
import { GroupKind } from '../groups/group'
10+
import { GroupType } from '../groups/group'
1111
import { GroupRole } from './../groups/grouprole'
1212

1313
const router = Router()
1414

1515
router.get('/:id', isAuthenticated, checkIdParam, getUser, (req, res) =>
1616
res.render('user/show', {
1717
userToShow: req.userToShow,
18-
GroupKind,
18+
GroupType,
1919
GroupRole,
2020
userId: (req.user as User).id,
2121
ROLES: ROLES

views/group/new.pug

+4-4
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ block content
5252
label(class='text-lg font-bold' for="pickerEnd") Befejezés ideje
5353
input(type="text", id="pickerEnd", name="endDate", required, data-input, class="flatpickr")
5454
div
55-
label(for="kind" class='text-lg font-bold') Csoport típusa
55+
label(for="groupType" class='text-lg font-bold') Csoport típusa
5656
br
57-
select(id="kind" name="kind" class='flatpickr')
58-
option(value=`${GroupKind.classic}` selected=(kind === GroupKind.classic || !kind)) Klasszikus
59-
option(value=`${GroupKind.private}` selected=(kind === GroupKind.private)) Privát
57+
select(id="groupType" name="groupType" class='flatpickr')
58+
option(value=`${GroupType.classic}` selected=(type === GroupType.classic || !type)) Klasszikus
59+
option(value=`${GroupType.private}` selected=(type === GroupType.private)) Privát
6060
ul
6161
li
6262
span(class='font-bold') Klasszikus -

views/group/show.pug

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ block content
8989
path(stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M8 11V7a4 4 0 118 0m-4 8v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2z')
9090
span Nyílt
9191
sup(title='Szabad a csatlakozás') ?
92-
if group.kind === GroupKind.private
92+
if group.type === GroupType.private
9393
li(class='flex flex-row items-center space-x-2')
9494
//- Heroicon name: user-group
9595
svg.h-6.w-6(xmlns='http://www.w3.org/2000/svg' fill='none' viewbox='0 0 24 24' stroke='currentColor')

views/user/show.pug

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ block content
2323
option(value=`${key}`, selected=key==userToShow.role) #{ROLES.get(key)}
2424
button(type="button", id="submitBtn", onclick=`updateRole(${userToShow.id})`, class='ml-2 btn btn-primary animate-hover') Módosítás
2525

26-
- const isPublic = (group) => group.kind === GroupKind.classic
26+
- const isPublic = (group) => group.type === GroupType.classic
2727
- const isOwner = (group) => group.groupRole === GroupRole.owner
2828
- const viewingSelf = userToShow.id === userId
2929
- const ownsGroup = (group) => group.ownerId === userId

0 commit comments

Comments
 (0)