mirror of
https://github.com/CaramelFur/Picsur.git
synced 2026-02-21 13:46:50 +01:00
refactor some names
This commit is contained in:
@@ -67,10 +67,10 @@ export class ImageDBService {
|
||||
public async delete(id: string): AsyncFailable<true> {
|
||||
try {
|
||||
const derivativesResult = await this.imageDerivativeRepo.delete({
|
||||
imageId: id,
|
||||
image_id: id,
|
||||
});
|
||||
const filesResult = await this.imageFileRepo.delete({
|
||||
imageId: id,
|
||||
image_id: id,
|
||||
});
|
||||
const result = await this.imageRepo.delete({ id });
|
||||
|
||||
|
||||
@@ -23,14 +23,14 @@ export class ImageFileDBService {
|
||||
mime: string,
|
||||
): AsyncFailable<true> {
|
||||
const imageFile = new EImageFileBackend();
|
||||
imageFile.imageId = imageId;
|
||||
imageFile.image_id = imageId;
|
||||
imageFile.type = type;
|
||||
imageFile.mime = mime;
|
||||
imageFile.data = file;
|
||||
|
||||
try {
|
||||
await this.imageFileRepo.upsert(imageFile, {
|
||||
conflictPaths: ['imageId', 'type'],
|
||||
conflictPaths: ['image_id', 'type'],
|
||||
});
|
||||
} catch (e) {
|
||||
return Fail(e);
|
||||
@@ -45,7 +45,7 @@ export class ImageFileDBService {
|
||||
): AsyncFailable<EImageFileBackend> {
|
||||
try {
|
||||
const found = await this.imageFileRepo.findOne({
|
||||
where: { imageId: imageId ?? '', type: type ?? '' },
|
||||
where: { image_id: imageId ?? '', type: type ?? '' },
|
||||
});
|
||||
|
||||
if (!found) return Fail('Image not found');
|
||||
@@ -61,7 +61,7 @@ export class ImageFileDBService {
|
||||
): AsyncFailable<string> {
|
||||
try {
|
||||
const found = await this.imageFileRepo.findOne({
|
||||
where: { imageId, type },
|
||||
where: { image_id: imageId, type },
|
||||
select: ['mime'],
|
||||
});
|
||||
|
||||
@@ -79,7 +79,7 @@ export class ImageFileDBService {
|
||||
file: Buffer,
|
||||
): AsyncFailable<EImageDerivativeBackend> {
|
||||
const imageDerivative = new EImageDerivativeBackend();
|
||||
imageDerivative.imageId = imageId;
|
||||
imageDerivative.image_id = imageId;
|
||||
imageDerivative.key = key;
|
||||
imageDerivative.mime = mime;
|
||||
imageDerivative.data = file;
|
||||
@@ -97,7 +97,7 @@ export class ImageFileDBService {
|
||||
): AsyncFailable<EImageDerivativeBackend | null> {
|
||||
try {
|
||||
return await this.imageDerivativeRepo.findOne({
|
||||
where: { imageId, key },
|
||||
where: { image_id: imageId, key },
|
||||
});
|
||||
} catch (e) {
|
||||
return Fail(e);
|
||||
@@ -110,7 +110,7 @@ export class ImageFileDBService {
|
||||
): AsyncFailable<string> {
|
||||
try {
|
||||
const found = await this.imageDerivativeRepo.findOne({
|
||||
where: { imageId, key },
|
||||
where: { image_id: imageId, key },
|
||||
select: ['mime'],
|
||||
});
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ export class UsrPreferenceService {
|
||||
try {
|
||||
// Upsert here, because we want to create a new record if it does not exist
|
||||
await this.usrPreferenceRepository.upsert(usrPreference, {
|
||||
conflictPaths: ['key', 'userId'],
|
||||
conflictPaths: ['key', 'user_id'],
|
||||
});
|
||||
} catch (e) {
|
||||
return Fail(e);
|
||||
@@ -74,7 +74,7 @@ export class UsrPreferenceService {
|
||||
let existing: EUsrPreferenceBackend | null;
|
||||
try {
|
||||
existing = await this.usrPreferenceRepository.findOne({
|
||||
where: { key: validatedKey as UsrPreference, userId: userid },
|
||||
where: { key: validatedKey as UsrPreference, user_id: userid },
|
||||
cache: 60000,
|
||||
});
|
||||
if (!existing) return null;
|
||||
@@ -97,7 +97,7 @@ export class UsrPreferenceService {
|
||||
if (HasFailed(unpacked)) return unpacked;
|
||||
return {
|
||||
...unpacked,
|
||||
user: result.data.userId,
|
||||
user: result.data.user_id,
|
||||
};
|
||||
},
|
||||
() => this.saveDefault(userid, validatedKey as UsrPreference),
|
||||
@@ -192,7 +192,7 @@ export class UsrPreferenceService {
|
||||
let verifySysPreference = new EUsrPreferenceBackend();
|
||||
verifySysPreference.key = validated.key;
|
||||
verifySysPreference.value = validated.value;
|
||||
verifySysPreference.userId = userid;
|
||||
verifySysPreference.user_id = userid;
|
||||
|
||||
// It should already be valid, but these two validators might go out of sync
|
||||
const result = EUsrPreferenceSchema.safeParse(verifySysPreference);
|
||||
|
||||
@@ -3,22 +3,22 @@ import { InjectRepository } from '@nestjs/typeorm';
|
||||
import * as bcrypt from 'bcrypt';
|
||||
import { SysPreference } from 'picsur-shared/dist/dto/sys-preferences.dto';
|
||||
import {
|
||||
AsyncFailable,
|
||||
Fail,
|
||||
HasFailed,
|
||||
HasSuccess
|
||||
AsyncFailable,
|
||||
Fail,
|
||||
HasFailed,
|
||||
HasSuccess
|
||||
} from 'picsur-shared/dist/types';
|
||||
import { makeUnique } from 'picsur-shared/dist/util/unique';
|
||||
import { Repository } from 'typeorm';
|
||||
import { Permissions } from '../../models/constants/permissions.const';
|
||||
import {
|
||||
DefaultRolesList,
|
||||
SoulBoundRolesList
|
||||
DefaultRolesList,
|
||||
SoulBoundRolesList
|
||||
} from '../../models/constants/roles.const';
|
||||
import {
|
||||
ImmutableUsersList,
|
||||
LockedLoginUsersList,
|
||||
UndeletableUsersList
|
||||
ImmutableUsersList,
|
||||
LockedLoginUsersList,
|
||||
UndeletableUsersList
|
||||
} from '../../models/constants/special-users.const';
|
||||
import { EUserBackend } from '../../models/entities/user.entity';
|
||||
import { GetCols } from '../../models/util/collection';
|
||||
@@ -52,7 +52,7 @@ export class UsersService {
|
||||
|
||||
let user = new EUserBackend();
|
||||
user.username = username;
|
||||
user.hashedPassword = hashedPassword;
|
||||
user.hashed_password = hashedPassword;
|
||||
if (byPassRoleCheck) {
|
||||
const rolesToAdd = roles ?? [];
|
||||
user.roles = makeUnique(rolesToAdd);
|
||||
@@ -145,7 +145,7 @@ export class UsersService {
|
||||
if (HasFailed(userToModify)) return userToModify;
|
||||
|
||||
const strength = await this.getBCryptStrength();
|
||||
userToModify.hashedPassword = await bcrypt.hash(password, strength);
|
||||
userToModify.hashed_password = await bcrypt.hash(password, strength);
|
||||
|
||||
try {
|
||||
userToModify = await this.usersRepository.save(userToModify);
|
||||
@@ -170,7 +170,7 @@ export class UsersService {
|
||||
return Fail('Wrong username');
|
||||
}
|
||||
|
||||
if (!(await bcrypt.compare(password, user.hashedPassword ?? '')))
|
||||
if (!(await bcrypt.compare(password, user.hashed_password ?? '')))
|
||||
return Fail('Wrong password');
|
||||
|
||||
return await this.findOne(user.id ?? '');
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { Column, Entity, Index, PrimaryGeneratedColumn, Unique } from 'typeorm';
|
||||
|
||||
@Entity()
|
||||
@Unique(['imageId', 'key'])
|
||||
@Unique(['image_id', 'key'])
|
||||
export class EImageDerivativeBackend {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
private _id?: string;
|
||||
|
||||
@Index()
|
||||
@Column({ nullable: false })
|
||||
imageId: string;
|
||||
image_id: string;
|
||||
|
||||
@Index()
|
||||
@Column({ nullable: false })
|
||||
|
||||
@@ -2,14 +2,14 @@ import { Column, Entity, Index, PrimaryGeneratedColumn, Unique } from 'typeorm';
|
||||
import { ImageFileType } from '../constants/image-file-types.const';
|
||||
|
||||
@Entity()
|
||||
@Unique(['imageId', 'type'])
|
||||
@Unique(['image_id', 'type'])
|
||||
export class EImageFileBackend {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
private _id?: string;
|
||||
|
||||
@Index()
|
||||
@Column({ nullable: false })
|
||||
imageId: string;
|
||||
image_id: string;
|
||||
|
||||
@Index()
|
||||
@Column({ nullable: false, enum: ImageFileType })
|
||||
|
||||
@@ -23,5 +23,5 @@ export class EUserBackend implements OverriddenEUser {
|
||||
roles: string[];
|
||||
|
||||
@Column({ nullable: false, select: false })
|
||||
hashedPassword?: string;
|
||||
hashed_password?: string;
|
||||
}
|
||||
|
||||
@@ -6,12 +6,12 @@ export const EUsrPreferenceSchema = z.object({
|
||||
id: IsEntityID().optional(),
|
||||
key: z.string(),
|
||||
value: z.string(),
|
||||
userId: IsEntityID(),
|
||||
user_id: IsEntityID(),
|
||||
});
|
||||
type EUsrPreference = z.infer<typeof EUsrPreferenceSchema>;
|
||||
|
||||
@Entity()
|
||||
@Unique(['key', 'userId'])
|
||||
@Unique(['key', 'user_id'])
|
||||
export class EUsrPreferenceBackend implements EUsrPreference {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id?: string;
|
||||
@@ -25,5 +25,5 @@ export class EUsrPreferenceBackend implements EUsrPreference {
|
||||
|
||||
@Index()
|
||||
@Column({ nullable: false })
|
||||
userId: string;
|
||||
user_id: string;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import { EUserBackend } from '../entities/user.entity';
|
||||
export function EUserBackend2EUser(
|
||||
eUser: EUserBackend,
|
||||
): EUser {
|
||||
if (eUser.hashedPassword === undefined)
|
||||
if (eUser.hashed_password === undefined)
|
||||
return eUser as EUser;
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user