mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-10 15:17:41 +00:00
Add generateRandomString helper function and remove nanoid dependency
This commit is contained in:
10
libs/common/src/helper/randomString.ts
Normal file
10
libs/common/src/helper/randomString.ts
Normal file
@ -0,0 +1,10 @@
|
||||
export function generateRandomString(length: number): string {
|
||||
const characters =
|
||||
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
||||
let randomString = '';
|
||||
for (let i = 0; i < length; i++) {
|
||||
const randomIndex = Math.floor(Math.random() * characters.length);
|
||||
randomString += characters.charAt(randomIndex);
|
||||
}
|
||||
return randomString;
|
||||
}
|
15
package-lock.json
generated
15
package-lock.json
generated
@ -28,7 +28,6 @@
|
||||
"helmet": "^7.1.0",
|
||||
"ioredis": "^5.3.2",
|
||||
"morgan": "^1.10.0",
|
||||
"nanoid": "^5.0.7",
|
||||
"nodemailer": "^6.9.10",
|
||||
"passport-jwt": "^4.0.1",
|
||||
"pg": "^8.11.3",
|
||||
@ -5255,20 +5254,6 @@
|
||||
"integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/fsevents": {
|
||||
"version": "2.3.3",
|
||||
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz",
|
||||
"integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==",
|
||||
"dev": true,
|
||||
"hasInstallScript": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"darwin"
|
||||
],
|
||||
"engines": {
|
||||
"node": "^8.16.0 || ^10.6.0 || >=11.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/function-bind": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz",
|
||||
|
@ -39,7 +39,6 @@
|
||||
"helmet": "^7.1.0",
|
||||
"ioredis": "^5.3.2",
|
||||
"morgan": "^1.10.0",
|
||||
"nanoid": "^5.0.7",
|
||||
"nodemailer": "^6.9.10",
|
||||
"passport-jwt": "^4.0.1",
|
||||
"pg": "^8.11.3",
|
||||
|
@ -18,6 +18,7 @@ import {
|
||||
import { SpaceEntity } from '@app/common/modules/space/entities';
|
||||
import { UpdateUnitNameDto } from '../dtos/update.unit.dto';
|
||||
import { UserSpaceRepository } from '@app/common/modules/user-space/repositories';
|
||||
import { generateRandomString } from '@app/common/helper/randomString';
|
||||
|
||||
@Injectable()
|
||||
export class UnitService {
|
||||
@ -284,10 +285,8 @@ export class UnitService {
|
||||
}
|
||||
async getUnitInvitationCode(unitUuid: string): Promise<any> {
|
||||
try {
|
||||
const { nanoid } = await import('nanoid');
|
||||
|
||||
// Generate a 6-character random invitation code
|
||||
const invitationCode = nanoid(6);
|
||||
const invitationCode = generateRandomString(6);
|
||||
|
||||
// Update the unit with the new invitation code
|
||||
await this.spaceRepository.update({ uuid: unitUuid }, { invitationCode });
|
||||
@ -304,6 +303,8 @@ export class UnitService {
|
||||
type: updatedUnit.spaceType.type,
|
||||
};
|
||||
} catch (err) {
|
||||
console.log('err', err);
|
||||
|
||||
if (err instanceof BadRequestException) {
|
||||
throw err;
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user