add isDeleted in backend, delete and undelete is activ by return

This commit is contained in:
ogerly 2022-02-22 14:45:43 +01:00
parent 99c2636772
commit 3b656898e1
6 changed files with 33 additions and 7 deletions

View File

@ -47,6 +47,8 @@ export default {
}) })
.then(() => { .then(() => {
this.$toasted.success('user is deleted') this.$toasted.success('user is deleted')
this.item.deletedAt = Date.now()
this.checked = false
}) })
.catch((error) => { .catch((error) => {
this.$toasted.error('user deleted error', error) this.$toasted.error('user deleted error', error)
@ -62,6 +64,8 @@ export default {
}) })
.then(() => { .then(() => {
this.$toasted.success('user is undeleted') this.$toasted.success('user is undeleted')
this.item.deletedAt = null
this.checked = false
}) })
.catch((error) => { .catch((error) => {
this.$toasted.error('user undeleted error', error) this.$toasted.error('user undeleted error', error)

View File

@ -1,12 +1,19 @@
import gql from 'graphql-tag' import gql from 'graphql-tag'
export const searchUsers = gql` export const searchUsers = gql`
query ($searchText: String!, $currentPage: Int, $pageSize: Int, $notActivated: Boolean) { query (
$searchText: String!
$currentPage: Int
$pageSize: Int
$notActivated: Boolean
$isDeleted: Boolean
) {
searchUsers( searchUsers(
searchText: $searchText searchText: $searchText
currentPage: $currentPage currentPage: $currentPage
pageSize: $pageSize pageSize: $pageSize
notActivated: $notActivated notActivated: $notActivated
isDeleted: $isDeleted
) { ) {
userCount userCount
userList { userList {

View File

@ -71,7 +71,6 @@ export default {
deletedUserSearch() { deletedUserSearch() {
this.filterDeletedUser = !this.filterDeletedUser this.filterDeletedUser = !this.filterDeletedUser
this.getUsers() this.getUsers()
alert('TODO: deleted user filter in search and check in backend ')
}, },
getUsers() { getUsers() {
this.$apollo this.$apollo
@ -82,7 +81,7 @@ export default {
currentPage: this.currentPage, currentPage: this.currentPage,
pageSize: this.perPage, pageSize: this.perPage,
notActivated: this.filterCheckedEmails, notActivated: this.filterCheckedEmails,
deletedUser: this.filterDeletedUser, isDeleted: this.filterDeletedUser,
}, },
}) })
.then((result) => { .then((result) => {

View File

@ -13,4 +13,7 @@ export default class SearchUsersArgs {
@Field(() => Boolean, { nullable: true }) @Field(() => Boolean, { nullable: true })
notActivated?: boolean notActivated?: boolean
@Field(() => Boolean, { nullable: true })
isDeleted?: boolean
} }

View File

@ -2,7 +2,7 @@
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import { Resolver, Query, Arg, Args, Authorized, Mutation, Ctx } from 'type-graphql' import { Resolver, Query, Arg, Args, Authorized, Mutation, Ctx } from 'type-graphql'
import { getCustomRepository, ObjectLiteral, Raw } from '@dbTools/typeorm' import { getCustomRepository, IsNull, Not, ObjectLiteral, Raw } from '@dbTools/typeorm'
import { UserAdmin, SearchUsersResult } from '../model/UserAdmin' import { UserAdmin, SearchUsersResult } from '../model/UserAdmin'
import { PendingCreation } from '../model/PendingCreation' import { PendingCreation } from '../model/PendingCreation'
import { CreatePendingCreations } from '../model/CreatePendingCreations' import { CreatePendingCreations } from '../model/CreatePendingCreations'
@ -32,7 +32,14 @@ export class AdminResolver {
@Authorized([RIGHTS.SEARCH_USERS]) @Authorized([RIGHTS.SEARCH_USERS])
@Query(() => SearchUsersResult) @Query(() => SearchUsersResult)
async searchUsers( async searchUsers(
@Args() { searchText, currentPage = 1, pageSize = 25, notActivated = false }: SearchUsersArgs, @Args()
{
searchText,
currentPage = 1,
pageSize = 25,
notActivated = false,
isDeleted = false,
}: SearchUsersArgs,
): Promise<SearchUsersResult> { ): Promise<SearchUsersResult> {
const userRepository = getCustomRepository(UserRepository) const userRepository = getCustomRepository(UserRepository)
@ -40,6 +47,9 @@ export class AdminResolver {
if (notActivated) { if (notActivated) {
filterCriteria.push({ emailChecked: false }) filterCriteria.push({ emailChecked: false })
} }
if (isDeleted) {
filterCriteria.push({ deletedAt: Not(IsNull()) })
}
// prevent overfetching data from db, select only needed columns // prevent overfetching data from db, select only needed columns
// prevent reading and transmitting data from db at least 300 Bytes // prevent reading and transmitting data from db at least 300 Bytes
// one of my example dataset shrink down from 342 Bytes to 42 Bytes, that's ~88% saved db bandwith // one of my example dataset shrink down from 342 Bytes to 42 Bytes, that's ~88% saved db bandwith

View File

@ -24,7 +24,7 @@ export class UserRepository extends Repository<User> {
currentPage: number, currentPage: number,
pageSize: number, pageSize: number,
): Promise<[User[], number]> { ): Promise<[User[], number]> {
return await this.createQueryBuilder('user') const query = await this.createQueryBuilder('user')
.select(select) .select(select)
.withDeleted() .withDeleted()
.where( .where(
@ -39,7 +39,10 @@ export class UserRepository extends Repository<User> {
) )
}), }),
) )
.andWhere(filterCriteria) filterCriteria.forEach((filter) => {
query.andWhere(filter)
})
return query
.take(pageSize) .take(pageSize)
.skip((currentPage - 1) * pageSize) .skip((currentPage - 1) * pageSize)
.getManyAndCount() .getManyAndCount()