@hedhog/admin 0.0.39 → 0.0.41
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/auth/auth.service.spec.d.ts +2 -0
- package/dist/auth/auth.service.spec.d.ts.map +1 -0
- package/dist/auth/auth.service.spec.js +163 -0
- package/dist/auth/auth.service.spec.js.map +1 -0
- package/dist/locale/locale.module.js +2 -2
- package/dist/locale/locale.module.js.map +1 -1
- package/dist/locale/locale.service.js +1 -1
- package/dist/locale/locale.service.js.map +1 -1
- package/dist/locale/locale.service.spec.d.ts +2 -0
- package/dist/locale/locale.service.spec.d.ts.map +1 -0
- package/dist/locale/locale.service.spec.js +171 -0
- package/dist/locale/locale.service.spec.js.map +1 -0
- package/dist/menu/menu.service.d.ts.map +1 -1
- package/dist/menu/menu.service.js +2 -0
- package/dist/menu/menu.service.js.map +1 -1
- package/dist/menu/menu.service.spec.d.ts +2 -0
- package/dist/menu/menu.service.spec.d.ts.map +1 -0
- package/dist/menu/menu.service.spec.js +196 -0
- package/dist/menu/menu.service.spec.js.map +1 -0
- package/dist/role/role.service.spec.d.ts +2 -0
- package/dist/role/role.service.spec.d.ts.map +1 -0
- package/dist/role/role.service.spec.js +343 -0
- package/dist/role/role.service.spec.js.map +1 -0
- package/dist/route/route.service.spec.d.ts +2 -0
- package/dist/route/route.service.spec.d.ts.map +1 -0
- package/dist/route/route.service.spec.js +235 -0
- package/dist/route/route.service.spec.js.map +1 -0
- package/dist/screen/screen.service.spec.d.ts +2 -0
- package/dist/screen/screen.service.spec.d.ts.map +1 -0
- package/dist/screen/screen.service.spec.js +242 -0
- package/dist/screen/screen.service.spec.js.map +1 -0
- package/dist/setting/settings.service.spec.d.ts +2 -0
- package/dist/setting/settings.service.spec.d.ts.map +1 -0
- package/dist/setting/settings.service.spec.js +147 -0
- package/dist/setting/settings.service.spec.js.map +1 -0
- package/dist/user/user.service.spec.d.ts +2 -0
- package/dist/user/user.service.spec.d.ts.map +1 -0
- package/dist/user/user.service.spec.js +239 -0
- package/dist/user/user.service.spec.js.map +1 -0
- package/package.json +1 -1
- package/src/migrations/migrate-02.ts +137 -137
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"settings.service.spec.js","sourceRoot":"","sources":["../../src/setting/settings.service.spec.ts"],"names":[],"mappings":";;AAAA,6CAAsD;AACtD,yDAAqD;AACrD,2CAA+C;AAC/C,mDAI4B;AAC5B,2CAAqD;AAKrD,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,IAAI,OAAwB,CAAC;IAC7B,IAAI,aAA4B,CAAC;IACjC,IAAI,iBAAoC,CAAC;IAEzC,UAAU,CAAC,KAAK,IAAI,EAAE;QACpB,MAAM,MAAM,GAAkB,MAAM,cAAI,CAAC,mBAAmB,CAAC;YAC3D,SAAS,EAAE;gBACT,kCAAe;gBACf;oBACE,OAAO,EAAE,sBAAa;oBACtB,QAAQ,EAAE;wBACR,QAAQ,EAAE;4BACR,UAAU,EAAE,IAAI,CAAC,EAAE,EAAE;4BACrB,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE;4BACjB,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE;4BACjB,UAAU,EAAE,IAAI,CAAC,EAAE,EAAE;yBACtB;wBACD,uBAAuB,EAAE,IAAI,CAAC,EAAE,EAAE;qBACnC;iBACF;gBACD;oBACE,OAAO,EAAE,8BAAiB;oBAC1B,QAAQ,EAAE;wBACR,QAAQ,EAAE,IAAI,CAAC,EAAE,EAAE;qBACpB;iBACF;aACF;SACF,CAAC,CAAC,OAAO,EAAE,CAAC;QAEb,OAAO,GAAG,MAAM,CAAC,GAAG,CAAkB,kCAAe,CAAC,CAAC;QACvD,aAAa,GAAG,MAAM,CAAC,GAAG,CAAgB,sBAAa,CAAC,CAAC;QACzD,iBAAiB,GAAG,MAAM,CAAC,GAAG,CAAoB,8BAAiB,CAAC,CAAC;IACvE,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,mBAAmB,EAAE,GAAG,EAAE;QAC3B,MAAM,CAAC,OAAO,CAAC,C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,EAAE,IAAI,EAAE,CAAC;YAE3C,MAAM,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CACrD,IAAI,4BAAmB,CACrB,iDAAiD,CAClD,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,+BAA+B,EAAE,KAAK,IAAI,EAAE;YAC7C,MAAM,SAAS,GAAc,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;YAE7C,IAAI;iBACD,KAAK,CAAC,aAAa,CAAC,QAAQ,EAAE,YAAY,CAAC;iBAC3C,iBAAiB,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC;YAEnC,MAAM,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;YAEhC,MAAM,CAAC,aAAa,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,oBAAoB,CAAC;gBAC7D,KAAK,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,SAAS,CAAC,GAAG,EAAE,EAAE;aACrC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"user.service.spec.d.ts","sourceRoot":"","sources":["../../src/user/user.service.spec.ts"],"names":[],"mappings":""}
|
@@ -0,0 +1,239 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const testing_1 = require("@nestjs/testing");
|
4
|
+
const user_service_1 = require("./user.service");
|
5
|
+
const prisma_1 = require("@hedhog/prisma");
|
6
|
+
const pagination_1 = require("@hedhog/pagination");
|
7
|
+
const common_1 = require("@nestjs/common");
|
8
|
+
const bcrypt_1 = require("bcrypt");
|
9
|
+
const user_constants_1 = require("./constants/user.constants");
|
10
|
+
jest.mock('bcrypt', () => ({
|
11
|
+
genSalt: jest.fn().mockResolvedValue('mockSalt'),
|
12
|
+
hash: jest.fn().mockResolvedValue('mockHashedPassword'),
|
13
|
+
}));
|
14
|
+
describe('UserService', () => {
|
15
|
+
let service;
|
16
|
+
let prismaService;
|
17
|
+
let paginationService;
|
18
|
+
beforeEach(async () => {
|
19
|
+
const module = await testing_1.Test.createTestingModule({
|
20
|
+
providers: [
|
21
|
+
user_service_1.UserService,
|
22
|
+
{
|
23
|
+
provide: prisma_1.PrismaService,
|
24
|
+
useValue: {
|
25
|
+
users: {
|
26
|
+
findUnique: jest.fn(),
|
27
|
+
create: jest.fn(),
|
28
|
+
update: jest.fn(),
|
29
|
+
deleteMany: jest.fn(),
|
30
|
+
},
|
31
|
+
role_users: {
|
32
|
+
deleteMany: jest.fn(),
|
33
|
+
createMany: jest.fn(),
|
34
|
+
},
|
35
|
+
createInsensitiveSearch: jest.fn(),
|
36
|
+
},
|
37
|
+
},
|
38
|
+
{
|
39
|
+
provide: pagination_1.PaginationService,
|
40
|
+
useValue: {
|
41
|
+
paginate: jest.fn(),
|
42
|
+
},
|
43
|
+
},
|
44
|
+
],
|
45
|
+
}).compile();
|
46
|
+
service = module.get(user_service_1.UserService);
|
47
|
+
prismaService = module.get(prisma_1.PrismaService);
|
48
|
+
paginationService = module.get(pagination_1.PaginationService);
|
49
|
+
});
|
50
|
+
it('should be defined', () => {
|
51
|
+
expect(service).toBeDefined();
|
52
|
+
});
|
53
|
+
describe('listRoles', () => {
|
54
|
+
it('should return paginated roles for a specific user', async () => {
|
55
|
+
const paginationParams = {
|
56
|
+
page: 1,
|
57
|
+
pageSize: 10,
|
58
|
+
search: '',
|
59
|
+
sortField: '',
|
60
|
+
sortOrder: pagination_1.PageOrderDirection.Asc,
|
61
|
+
fields: '',
|
62
|
+
};
|
63
|
+
const mockPaginatedRoles = {
|
64
|
+
data: [],
|
65
|
+
total: 10,
|
66
|
+
lastPage: 1,
|
67
|
+
page: 1,
|
68
|
+
prev: 0,
|
69
|
+
next: 2,
|
70
|
+
pageSize: 10,
|
71
|
+
};
|
72
|
+
jest
|
73
|
+
.spyOn(paginationService, 'paginate')
|
74
|
+
.mockResolvedValue(mockPaginatedRoles);
|
75
|
+
const result = await service.listRoles(1, paginationParams);
|
76
|
+
expect(paginationService.paginate).toHaveBeenCalledWith(prismaService.roles, paginationParams, {
|
77
|
+
include: {
|
78
|
+
role_users: {
|
79
|
+
where: { user_id: 1 },
|
80
|
+
select: { user_id: true, role_id: true },
|
81
|
+
},
|
82
|
+
},
|
83
|
+
});
|
84
|
+
expect(result).toEqual(mockPaginatedRoles);
|
85
|
+
});
|
86
|
+
});
|
87
|
+
describe('updateRoles', () => {
|
88
|
+
it('should update user roles', async () => {
|
89
|
+
const updateIdsDTO = { ids: [1, 2] };
|
90
|
+
jest
|
91
|
+
.spyOn(prismaService.role_users, 'deleteMany')
|
92
|
+
.mockResolvedValue({ count: 1 });
|
93
|
+
jest
|
94
|
+
.spyOn(prismaService.role_users, 'createMany')
|
95
|
+
.mockResolvedValue({ count: 2 });
|
96
|
+
await service.updateRoles(1, updateIdsDTO);
|
97
|
+
expect(prismaService.role_users.deleteMany).toHaveBeenCalledWith({
|
98
|
+
where: { user_id: 1 },
|
99
|
+
});
|
100
|
+
expect(prismaService.role_users.createMany).toHaveBeenCalledWith({
|
101
|
+
data: [
|
102
|
+
{ user_id: 1, role_id: 1 },
|
103
|
+
{ user_id: 1, role_id: 2 },
|
104
|
+
],
|
105
|
+
skipDuplicates: true,
|
106
|
+
});
|
107
|
+
});
|
108
|
+
});
|
109
|
+
describe('getUsers', () => {
|
110
|
+
it('should return paginated users', async () => {
|
111
|
+
const paginationParams = {
|
112
|
+
page: 1,
|
113
|
+
pageSize: 10,
|
114
|
+
search: '',
|
115
|
+
sortField: '',
|
116
|
+
sortOrder: pagination_1.PageOrderDirection.Asc,
|
117
|
+
fields: '',
|
118
|
+
};
|
119
|
+
const mockPaginatedUsers = {
|
120
|
+
data: [],
|
121
|
+
total: 10,
|
122
|
+
lastPage: 1,
|
123
|
+
page: 1,
|
124
|
+
prev: 0,
|
125
|
+
next: 2,
|
126
|
+
pageSize: 10,
|
127
|
+
};
|
128
|
+
jest.spyOn(prismaService, 'createInsensitiveSearch').mockReturnValue([]);
|
129
|
+
jest
|
130
|
+
.spyOn(paginationService, 'paginate')
|
131
|
+
.mockResolvedValue(mockPaginatedUsers);
|
132
|
+
const result = await service.getUsers(paginationParams);
|
133
|
+
expect(prismaService.createInsensitiveSearch).toHaveBeenCalledWith(['name', 'email'], paginationParams);
|
134
|
+
expect(paginationService.paginate).toHaveBeenCalledWith(prismaService.users, paginationParams, { where: { OR: [] } });
|
135
|
+
expect(result).toEqual(mockPaginatedUsers);
|
136
|
+
});
|
137
|
+
});
|
138
|
+
describe('get', () => {
|
139
|
+
it('should return a specific user by ID', async () => {
|
140
|
+
const mockUser = {
|
141
|
+
id: 1,
|
142
|
+
name: 'Test User',
|
143
|
+
email: 'user@email.com',
|
144
|
+
password: 'hashedpassword',
|
145
|
+
created_at: new Date(),
|
146
|
+
updated_at: new Date(),
|
147
|
+
multifactor_id: null,
|
148
|
+
code: null,
|
149
|
+
};
|
150
|
+
jest.spyOn(prismaService.users, 'findUnique').mockResolvedValue(mockUser);
|
151
|
+
const result = await service.get(1);
|
152
|
+
expect(prismaService.users.findUnique).toHaveBeenCalledWith({
|
153
|
+
where: { id: 1 },
|
154
|
+
});
|
155
|
+
expect(result).toEqual(mockUser);
|
156
|
+
});
|
157
|
+
});
|
158
|
+
describe('hashPassword', () => {
|
159
|
+
it('should hash the password correctly', async () => {
|
160
|
+
const password = 'plainPassword';
|
161
|
+
const result = await service.hashPassword(password);
|
162
|
+
expect(bcrypt_1.genSalt).toHaveBeenCalledWith(user_constants_1.SALT_ROUNDS);
|
163
|
+
expect(bcrypt_1.hash).toHaveBeenCalledWith(password, 'mockSalt');
|
164
|
+
expect(result).toEqual('mockHashedPassword');
|
165
|
+
});
|
166
|
+
});
|
167
|
+
describe('create', () => {
|
168
|
+
it('should create a new user with hashed password', async () => {
|
169
|
+
const createDTO = {
|
170
|
+
email: 'test@test.com',
|
171
|
+
name: 'Test User',
|
172
|
+
password: 'password123',
|
173
|
+
};
|
174
|
+
const mockUser = {
|
175
|
+
id: 1,
|
176
|
+
name: 'Test User',
|
177
|
+
email: 'user@email.com',
|
178
|
+
password: 'hashedpassword',
|
179
|
+
created_at: new Date(),
|
180
|
+
updated_at: new Date(),
|
181
|
+
multifactor_id: null,
|
182
|
+
code: null,
|
183
|
+
};
|
184
|
+
jest.spyOn(prismaService.users, 'create').mockResolvedValue(mockUser);
|
185
|
+
const result = await service.create(createDTO);
|
186
|
+
expect(prismaService.users.create).toHaveBeenCalledWith({
|
187
|
+
data: {
|
188
|
+
email: createDTO.email,
|
189
|
+
name: createDTO.name,
|
190
|
+
password: 'mockHashedPassword',
|
191
|
+
},
|
192
|
+
});
|
193
|
+
expect(result).toEqual(mockUser);
|
194
|
+
});
|
195
|
+
});
|
196
|
+
describe('update', () => {
|
197
|
+
it('should update an existing user', async () => {
|
198
|
+
const updateDTO = { name: 'Updated User' };
|
199
|
+
const updateInput = { id: 1, data: updateDTO };
|
200
|
+
const mockUser = {
|
201
|
+
id: 1,
|
202
|
+
name: 'Updated User',
|
203
|
+
email: 'user@email.com',
|
204
|
+
password: 'hashedpassword',
|
205
|
+
created_at: new Date(),
|
206
|
+
updated_at: new Date(),
|
207
|
+
multifactor_id: null,
|
208
|
+
code: null,
|
209
|
+
};
|
210
|
+
jest.spyOn(prismaService.users, 'update').mockResolvedValue(mockUser);
|
211
|
+
const result = await service.update(updateInput);
|
212
|
+
expect(prismaService.users.update).toHaveBeenCalledWith({
|
213
|
+
where: { id: updateInput.id },
|
214
|
+
data: updateInput.data,
|
215
|
+
});
|
216
|
+
expect(result).toEqual(mockUser);
|
217
|
+
});
|
218
|
+
});
|
219
|
+
describe('delete', () => {
|
220
|
+
it('should throw an error if no ids are provided', async () => {
|
221
|
+
const deleteDTO = { ids: null };
|
222
|
+
await expect(service.delete(deleteDTO)).rejects.toThrow(new common_1.BadRequestException('You must select at least one user to delete.'));
|
223
|
+
});
|
224
|
+
it('should delete users by ids', async () => {
|
225
|
+
const deleteDTO = { ids: [1, 2] };
|
226
|
+
jest
|
227
|
+
.spyOn(prismaService.users, 'deleteMany')
|
228
|
+
.mockResolvedValue({ count: 2 });
|
229
|
+
await service.delete(deleteDTO);
|
230
|
+
expect(prismaService.users.deleteMany).toHaveBeenCalledWith({
|
231
|
+
where: {
|
232
|
+
id: { in: deleteDTO.ids },
|
233
|
+
email: { not: { startsWith: 'root@' } },
|
234
|
+
},
|
235
|
+
});
|
236
|
+
});
|
237
|
+
});
|
238
|
+
});
|
239
|
+
//# sourceMappingURL=user.service.spec.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"user.service.spec.js","sourceRoot":"","sources":["../../src/user/user.service.spec.ts"],"names":[],"mappings":";;AAAA,6CAAsD;AACtD,iDAA6C;AAC7C,2CAA+C;AAC/C,mDAI4B;AAC5B,2CAAqD;AAKrD,mCAAuC;AACvC,+DAAyD;AAEzD,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,EAAE,CAAC,CAAC;IACzB,OAAO,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,UAAU,CAAC;IAChD,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,oBAAoB,CAAC;CACxD,CAAC,CAAC,CAAC;AAEJ,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;IAC3B,IAAI,OAAoB,CAAC;IACzB,IAAI,aAA4B,CAAC;IACjC,IAAI,iBAAoC,CAAC;IAEzC,UAAU,CAAC,KAAK,IAAI,EAAE;QACpB,MAAM,MAAM,GAAkB,MAAM,cAAI,CAAC,mBAAmB,CAAC;YAC3D,SAAS,EAAE;gBACT,0BAAW;gBACX;oBACE,OAAO,EAAE,sBAAa;oBACtB,QAAQ,EAAE;wBACR,KAAK,EAAE;4BACL,UA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EAAE,CAAC,8CAA8C,EAAE,KAAK,IAAI,EAAE;YAC5D,MAAM,SAAS,GAAc,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC;YAE3C,MAAM,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CACrD,IAAI,4BAAmB,CAAC,8CAA8C,CAAC,CACxE,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,4BAA4B,EAAE,KAAK,IAAI,EAAE;YAC1C,MAAM,SAAS,GAAc,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;YAE7C,IAAI;iBACD,KAAK,CAAC,aAAa,CAAC,KAAK,EAAE,YAAY,CAAC;iBACxC,iBAAiB,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC;YAEnC,MAAM,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;YAEhC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,oBAAoB,CAAC;gBAC1D,KAAK,EAAE;oBACL,EAAE,EAAE,EAAE,EAAE,EAAE,SAAS,CAAC,GAAG,EAAE;oBACzB,KAAK,EAAE,EAAE,GAAG,EAAE,EAAE,UAAU,EAAE,OAAO,EAAE,EAAE;iBACxC;aACF,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
@@ -1,137 +1,137 @@
|
|
1
|
-
import {
|
2
|
-
MigrationInterface,
|
3
|
-
QueryRunner,
|
4
|
-
Table,
|
5
|
-
TableForeignKey,
|
6
|
-
} from 'typeorm';
|
7
|
-
import { idColumn, timestampColumn } from '@hedhog/utils';
|
8
|
-
|
9
|
-
export class Migrate implements MigrationInterface {
|
10
|
-
public async up(queryRunner: QueryRunner): Promise<void> {
|
11
|
-
await await queryRunner.createTable(
|
12
|
-
new Table({
|
13
|
-
name: 'translation_namespaces',
|
14
|
-
columns: [
|
15
|
-
idColumn(),
|
16
|
-
{
|
17
|
-
name: 'name',
|
18
|
-
type: 'varchar',
|
19
|
-
isNullable: false,
|
20
|
-
},
|
21
|
-
timestampColumn(),
|
22
|
-
timestampColumn('updated_at'),
|
23
|
-
],
|
24
|
-
}),
|
25
|
-
true,
|
26
|
-
);
|
27
|
-
|
28
|
-
await await queryRunner.manager
|
29
|
-
.createQueryBuilder()
|
30
|
-
.insert()
|
31
|
-
.into('translation_namespaces')
|
32
|
-
.values([{ name: 'translation' }])
|
33
|
-
.execute();
|
34
|
-
|
35
|
-
await queryRunner.createTable(
|
36
|
-
new Table({
|
37
|
-
name: 'translations',
|
38
|
-
columns: [
|
39
|
-
idColumn(),
|
40
|
-
{
|
41
|
-
name: 'locale_id',
|
42
|
-
type: 'int',
|
43
|
-
isNullable: false,
|
44
|
-
unsigned: true,
|
45
|
-
},
|
46
|
-
{
|
47
|
-
name: 'namespace_id',
|
48
|
-
type: 'int',
|
49
|
-
isNullable: false,
|
50
|
-
unsigned: true,
|
51
|
-
},
|
52
|
-
{
|
53
|
-
name: 'name',
|
54
|
-
type: 'varchar',
|
55
|
-
isNullable: false,
|
56
|
-
},
|
57
|
-
{
|
58
|
-
name: 'value',
|
59
|
-
type: 'varchar',
|
60
|
-
isNullable: false,
|
61
|
-
},
|
62
|
-
timestampColumn(),
|
63
|
-
timestampColumn('updated_at'),
|
64
|
-
],
|
65
|
-
uniques: [
|
66
|
-
{
|
67
|
-
columnNames: ['locale_id', 'namespace_id', 'name'],
|
68
|
-
},
|
69
|
-
],
|
70
|
-
foreignKeys: [
|
71
|
-
new TableForeignKey({
|
72
|
-
columnNames: ['locale_id'],
|
73
|
-
referencedTableName: 'locales',
|
74
|
-
referencedColumnNames: ['id'],
|
75
|
-
onDelete: 'CASCADE',
|
76
|
-
}),
|
77
|
-
new TableForeignKey({
|
78
|
-
columnNames: ['namespace_id'],
|
79
|
-
referencedTableName: 'translation_namespaces',
|
80
|
-
referencedColumnNames: ['id'],
|
81
|
-
onDelete: 'CASCADE',
|
82
|
-
}),
|
83
|
-
],
|
84
|
-
}),
|
85
|
-
true,
|
86
|
-
);
|
87
|
-
|
88
|
-
await await queryRunner.manager
|
89
|
-
.createQueryBuilder()
|
90
|
-
.insert()
|
91
|
-
.into('translations', ['locale_id', 'namespace_id', 'name', 'value'])
|
92
|
-
.values([
|
93
|
-
{
|
94
|
-
locale_id: 1,
|
95
|
-
namespace_id: 1,
|
96
|
-
name: 'slogan',
|
97
|
-
value: 'Administration Panel',
|
98
|
-
},
|
99
|
-
{
|
100
|
-
locale_id: 1,
|
101
|
-
namespace_id: 1,
|
102
|
-
name: 'en',
|
103
|
-
value: 'English',
|
104
|
-
},
|
105
|
-
{
|
106
|
-
locale_id: 1,
|
107
|
-
namespace_id: 1,
|
108
|
-
name: 'pt',
|
109
|
-
value: 'Portuguese',
|
110
|
-
},
|
111
|
-
{
|
112
|
-
locale_id: 2,
|
113
|
-
namespace_id: 1,
|
114
|
-
name: 'slogan',
|
115
|
-
value: 'Painel de Administração',
|
116
|
-
},
|
117
|
-
{
|
118
|
-
locale_id: 2,
|
119
|
-
namespace_id: 1,
|
120
|
-
name: 'en',
|
121
|
-
value: 'Inglês',
|
122
|
-
},
|
123
|
-
{
|
124
|
-
locale_id: 2,
|
125
|
-
namespace_id: 1,
|
126
|
-
name: 'pt',
|
127
|
-
value: 'Português',
|
128
|
-
},
|
129
|
-
])
|
130
|
-
.execute();
|
131
|
-
}
|
132
|
-
|
133
|
-
public async down(queryRunner: QueryRunner): Promise<void> {
|
134
|
-
await queryRunner.dropTable('translations');
|
135
|
-
await queryRunner.dropTable('translation_namespaces');
|
136
|
-
}
|
137
|
-
}
|
1
|
+
import {
|
2
|
+
MigrationInterface,
|
3
|
+
QueryRunner,
|
4
|
+
Table,
|
5
|
+
TableForeignKey,
|
6
|
+
} from 'typeorm';
|
7
|
+
import { idColumn, timestampColumn } from '@hedhog/utils';
|
8
|
+
|
9
|
+
export class Migrate implements MigrationInterface {
|
10
|
+
public async up(queryRunner: QueryRunner): Promise<void> {
|
11
|
+
await await queryRunner.createTable(
|
12
|
+
new Table({
|
13
|
+
name: 'translation_namespaces',
|
14
|
+
columns: [
|
15
|
+
idColumn(),
|
16
|
+
{
|
17
|
+
name: 'name',
|
18
|
+
type: 'varchar',
|
19
|
+
isNullable: false,
|
20
|
+
},
|
21
|
+
timestampColumn(),
|
22
|
+
timestampColumn('updated_at'),
|
23
|
+
],
|
24
|
+
}),
|
25
|
+
true,
|
26
|
+
);
|
27
|
+
|
28
|
+
await await queryRunner.manager
|
29
|
+
.createQueryBuilder()
|
30
|
+
.insert()
|
31
|
+
.into('translation_namespaces')
|
32
|
+
.values([{ name: 'translation' }])
|
33
|
+
.execute();
|
34
|
+
|
35
|
+
await queryRunner.createTable(
|
36
|
+
new Table({
|
37
|
+
name: 'translations',
|
38
|
+
columns: [
|
39
|
+
idColumn(),
|
40
|
+
{
|
41
|
+
name: 'locale_id',
|
42
|
+
type: 'int',
|
43
|
+
isNullable: false,
|
44
|
+
unsigned: true,
|
45
|
+
},
|
46
|
+
{
|
47
|
+
name: 'namespace_id',
|
48
|
+
type: 'int',
|
49
|
+
isNullable: false,
|
50
|
+
unsigned: true,
|
51
|
+
},
|
52
|
+
{
|
53
|
+
name: 'name',
|
54
|
+
type: 'varchar',
|
55
|
+
isNullable: false,
|
56
|
+
},
|
57
|
+
{
|
58
|
+
name: 'value',
|
59
|
+
type: 'varchar',
|
60
|
+
isNullable: false,
|
61
|
+
},
|
62
|
+
timestampColumn(),
|
63
|
+
timestampColumn('updated_at'),
|
64
|
+
],
|
65
|
+
uniques: [
|
66
|
+
{
|
67
|
+
columnNames: ['locale_id', 'namespace_id', 'name'],
|
68
|
+
},
|
69
|
+
],
|
70
|
+
foreignKeys: [
|
71
|
+
new TableForeignKey({
|
72
|
+
columnNames: ['locale_id'],
|
73
|
+
referencedTableName: 'locales',
|
74
|
+
referencedColumnNames: ['id'],
|
75
|
+
onDelete: 'CASCADE',
|
76
|
+
}),
|
77
|
+
new TableForeignKey({
|
78
|
+
columnNames: ['namespace_id'],
|
79
|
+
referencedTableName: 'translation_namespaces',
|
80
|
+
referencedColumnNames: ['id'],
|
81
|
+
onDelete: 'CASCADE',
|
82
|
+
}),
|
83
|
+
],
|
84
|
+
}),
|
85
|
+
true,
|
86
|
+
);
|
87
|
+
|
88
|
+
await await queryRunner.manager
|
89
|
+
.createQueryBuilder()
|
90
|
+
.insert()
|
91
|
+
.into('translations', ['locale_id', 'namespace_id', 'name', 'value'])
|
92
|
+
.values([
|
93
|
+
{
|
94
|
+
locale_id: 1,
|
95
|
+
namespace_id: 1,
|
96
|
+
name: 'slogan',
|
97
|
+
value: 'Administration Panel',
|
98
|
+
},
|
99
|
+
{
|
100
|
+
locale_id: 1,
|
101
|
+
namespace_id: 1,
|
102
|
+
name: 'en',
|
103
|
+
value: 'English',
|
104
|
+
},
|
105
|
+
{
|
106
|
+
locale_id: 1,
|
107
|
+
namespace_id: 1,
|
108
|
+
name: 'pt',
|
109
|
+
value: 'Portuguese',
|
110
|
+
},
|
111
|
+
{
|
112
|
+
locale_id: 2,
|
113
|
+
namespace_id: 1,
|
114
|
+
name: 'slogan',
|
115
|
+
value: 'Painel de Administração',
|
116
|
+
},
|
117
|
+
{
|
118
|
+
locale_id: 2,
|
119
|
+
namespace_id: 1,
|
120
|
+
name: 'en',
|
121
|
+
value: 'Inglês',
|
122
|
+
},
|
123
|
+
{
|
124
|
+
locale_id: 2,
|
125
|
+
namespace_id: 1,
|
126
|
+
name: 'pt',
|
127
|
+
value: 'Português',
|
128
|
+
},
|
129
|
+
])
|
130
|
+
.execute();
|
131
|
+
}
|
132
|
+
|
133
|
+
public async down(queryRunner: QueryRunner): Promise<void> {
|
134
|
+
await queryRunner.dropTable('translations');
|
135
|
+
await queryRunner.dropTable('translation_namespaces');
|
136
|
+
}
|
137
|
+
}
|