Skip to content

Commit 32fedf1

Browse files
committed
feat: user role service bulk create
1 parent db4d6b9 commit 32fedf1

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

src/controllers/UserRole/service.ts

+31-5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,32 @@ class UserRoleService {
2525
return data
2626
}
2727

28+
/**
29+
*
30+
* @param arrayFormData - formData array []
31+
* @param txn - Transaction
32+
*/
33+
public static async bulkCreate(
34+
arrayFormData: UserRoleAttributes[],
35+
txn?: Transaction
36+
) {
37+
const newFormData = []
38+
if (Array.isArray(arrayFormData)) {
39+
for (let i = 0; i < arrayFormData.length; i += 1) {
40+
const formData = arrayFormData[i]
41+
42+
const value = useValidation(schema.create, formData)
43+
newFormData.push(value)
44+
}
45+
}
46+
47+
const data = await UserRole.bulkCreate(newFormData, {
48+
transaction: txn,
49+
})
50+
51+
return data
52+
}
53+
2854
/**
2955
*
3056
* @param formData
@@ -51,7 +77,7 @@ class UserRoleService {
5177
await UserRole.destroy({
5278
where: {
5379
UserId: {
54-
[Op.in]: id,
80+
[Op.in]: [id],
5581
},
5682
},
5783
})
@@ -60,16 +86,16 @@ class UserRoleService {
6086
/**
6187
*
6288
* @param id
63-
* @param roles Array of String
89+
* @param Roles Array of String
6490
* @example
65-
* roles = ['id_1', 'id_2']
91+
* Roles = ['id_1', 'id_2']
6692
*/
67-
public static async deleteNotInRoleId(id: string, roles: []) {
93+
public static async deleteNotInRoleId(id: string, Roles: []) {
6894
await UserRole.destroy({
6995
where: {
7096
UserId: id,
7197
RoleId: {
72-
[Op.notIn]: roles,
98+
[Op.notIn]: Roles,
7399
},
74100
},
75101
})

0 commit comments

Comments
 (0)