Skip to content

Commit

Permalink
feat: add isAnonymous field to user schema
Browse files Browse the repository at this point in the history
  • Loading branch information
CatiaAntunes96 committed Feb 17, 2023
1 parent fdb775a commit 5fdb7a1
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
5 changes: 3 additions & 2 deletions backend/src/modules/auth/controller/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,9 @@ export default class AuthController {
})
@Post('registerGuest')
async registerGuest(@Body() guestUserData: CreateGuestUserDto) {
const { _id } = await this.registerAuthApp.createGuestUser(guestUserData);
const { board } = guestUserData;
const { _id: user } = await this.registerAuthApp.createGuestUser(guestUserData);

return { user: _id, board: guestUserData.board };
return { user, board };
}
}
3 changes: 3 additions & 0 deletions backend/src/modules/users/entities/user.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ export default class User extends BaseModel {

@Prop({ nullable: true })
providerAccountCreatedAt?: Date;

@Prop({ default: false })
isAnonymous: boolean;
}

export const UserSchema = SchemaFactory.createForClass(User);
3 changes: 2 additions & 1 deletion backend/src/modules/users/repository/user.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ export class UserRepository
}

getAllWithPagination(page: number, size: number, searchUser?: string) {
let query: FilterQuery<UserDocument>;
let query: FilterQuery<UserDocument> = { isAnonymous: false || undefined };

if (searchUser) {
query = {
isAnonymous: false || undefined,
$or: [
{ firstName: { $regex: new RegExp('^.*' + searchUser + '.*$'), $options: 'i' } },
{ lastName: { $regex: new RegExp('^.*' + searchUser + '.*$'), $options: 'i' } },
Expand Down
11 changes: 8 additions & 3 deletions backend/src/modules/users/services/create.user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { CreateUserService } from '../interfaces/services/create.user.service.in
import { TYPES } from '../interfaces/types';
import { UserRepositoryInterface } from '../repository/user.repository.interface';
import CreateGuestUserDto from '../dto/create.guest.user.dto';
import faker from '@faker-js/faker';

@Injectable()
export default class CreateUserServiceImpl implements CreateUserService {
Expand All @@ -19,23 +20,27 @@ export default class CreateUserServiceImpl implements CreateUserService {
strategy: '',
isSAdmin: false,
isDeleted: false,
joinedAt: new Date()
joinedAt: new Date(),
isAnonymous: false
};

return this.userRepository.create(user);
}

createGuest(guestUserData: CreateGuestUserDto) {
const { firstName, lastName } = guestUserData;

const email = faker.internet.email(firstName, lastName, '', { allowSpecialCharacters: true });
const user: User = {
firstName,
lastName: lastName ?? '',
password: '',
email: '',
email: email,
strategy: '',
isSAdmin: false,
isDeleted: false,
joinedAt: new Date()
joinedAt: new Date(),
isAnonymous: true
};

return this.userRepository.create(user);
Expand Down
3 changes: 2 additions & 1 deletion backend/src/modules/users/services/get.user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ export default class GetUserServiceImpl implements GetUserService {
return this.userRepository.findAll(
{
password: 0,
currentHashedRefreshToken: 0
currentHashedRefreshToken: 0,
isAnonymous: 0
},
{ firstName: 'asc', lastName: 'asc' }
);
Expand Down

0 comments on commit 5fdb7a1

Please sign in to comment.