Skip to content

Commit

Permalink
Schedules
Browse files Browse the repository at this point in the history
  • Loading branch information
Fi1osof committed Mar 14, 2021
1 parent b810566 commit 33596c1
Show file tree
Hide file tree
Showing 39 changed files with 1,404 additions and 163 deletions.
32 changes: 16 additions & 16 deletions server/nexus/generated/nexus.ts
Expand Up @@ -777,18 +777,18 @@ export interface NexusGenObjects {
}
Schedule: {
// root type
end?: NexusGenRootTypes['ScheduleData'] | null // ScheduleData
end: NexusGenRootTypes['ScheduleData'] // ScheduleData!
start: NexusGenRootTypes['ScheduleData'] // ScheduleData!
}
ScheduleData: {
// root type
day?: number | null // Int
hour?: number | null // Int
minute?: number | null // Int
month?: number | null // Int
second?: number | null // Int
weekDay?: number | null // Int
year?: number | null // Int
day: number // Int!
hour: number // Int!
minute: number // Int!
month: number // Int!
second: number // Int!
weekDay: number // Int!
year: number // Int!
}
Schedules: {
// root type
Expand Down Expand Up @@ -1054,18 +1054,18 @@ export interface NexusGenFieldTypes {
}
Schedule: {
// field return type
end: NexusGenRootTypes['ScheduleData'] | null // ScheduleData
end: NexusGenRootTypes['ScheduleData'] // ScheduleData!
start: NexusGenRootTypes['ScheduleData'] // ScheduleData!
}
ScheduleData: {
// field return type
day: number | null // Int
hour: number | null // Int
minute: number | null // Int
month: number | null // Int
second: number | null // Int
weekDay: number | null // Int
year: number | null // Int
day: number // Int!
hour: number // Int!
minute: number // Int!
month: number // Int!
second: number // Int!
weekDay: number // Int!
year: number // Int!
}
Schedules: {
// field return type
Expand Down
16 changes: 8 additions & 8 deletions server/nexus/generated/schema.graphql
Expand Up @@ -568,21 +568,21 @@ type Review implements ResourceInterface {
Время работы
"""
type Schedule {
end: ScheduleData
end: ScheduleData!
start: ScheduleData!
}

"""
Данные времени работы
"""
type ScheduleData {
day: Int
hour: Int
minute: Int
month: Int
second: Int
weekDay: Int
year: Int
day: Int!
hour: Int!
minute: Int!
month: Int!
second: Int!
weekDay: Int!
year: Int!
}

"""
Expand Down
16 changes: 8 additions & 8 deletions server/nexus/types/Resource/Company/Schedule/index.ts
Expand Up @@ -4,13 +4,13 @@ export const ScheduleData = objectType({
name: 'ScheduleData',
description: 'Данные времени работы',
definition(t) {
t.int('year')
t.int('month')
t.int('day')
t.int('hour')
t.int('minute')
t.int('second')
t.int('weekDay')
t.nonNull.int('year')
t.nonNull.int('month')
t.nonNull.int('day')
t.nonNull.int('hour')
t.nonNull.int('minute')
t.nonNull.int('second')
t.nonNull.int('weekDay')
},
})

Expand All @@ -21,7 +21,7 @@ export const Schedule = objectType({
t.nonNull.field('start', {
type: 'ScheduleData',
})
t.field('end', {
t.nonNull.field('end', {
type: 'ScheduleData',
})
},
Expand Down
101 changes: 89 additions & 12 deletions server/nexus/types/Resource/Company/index.ts
Expand Up @@ -147,18 +147,44 @@ export const Company = objectType({

if (parent.properties) {
try {
const {
schedule: Schedule,
schedule_men: ScheduleMen,
schedule_women: ScheduleWomen,
schedule_family: ScheduleFamily,
} = JSON.parse(parent.properties)

Schedules = {
Schedule,
ScheduleMen,
ScheduleWomen,
ScheduleFamily,
const data = JSON.parse(parent.properties) as {
schedule: NexusGenObjects['Schedule'][] | null
schedule_men: NexusGenObjects['Schedule'][] | null
schedule_women: NexusGenObjects['Schedule'][] | null
schedule_family: NexusGenObjects['Schedule'][] | null
} | null

if (data && typeof data === 'object' && !Array.isArray(data)) {
const {
schedule: Schedule,
schedule_men: ScheduleMen,
schedule_women: ScheduleWomen,
schedule_family: ScheduleFamily,
} = data

Schedules = {
Schedule: Schedule
? Schedule.map((n: NexusGenObjects['Schedule'], index) =>
prepareShedule(n, index)
).filter((n) => n)
: null,
ScheduleMen: ScheduleMen
? ScheduleMen.map((n: NexusGenObjects['Schedule'], index) =>
prepareShedule(n, index)
).filter((n) => n)
: null,
ScheduleWomen: ScheduleWomen
? ScheduleWomen.map((n: NexusGenObjects['Schedule'], index) =>
prepareShedule(n, index)
).filter((n) => n)
: null,
ScheduleFamily: ScheduleFamily
? ScheduleFamily.map(
(n: NexusGenObjects['Schedule'], index) =>
prepareShedule(n, index)
).filter((n) => n)
: null,
}
}
} catch (error) {
console.error('Company::Schedules JSON parse error', error)
Expand All @@ -175,3 +201,54 @@ export const Company = objectType({
})
},
})

function prepareShedule(
Schedule: NexusGenObjects['Schedule'] | null,
index: number
): NexusGenObjects['Schedule'] | null {
if (!Schedule) {
return null
}

const {
start: {
day: dayStart = 0,
hour: hourStart = 0,
minute: minuteStart = 0,
month: monthStart = 0,
second: secondStart = 0,
weekDay: weekDayStart = index,
year: yearStart = 0,
},
end: {
day: dayEnd = 0,
hour: hourEnd = 0,
minute: minuteEnd = 0,
month: monthEnd = 0,
second: secondEnd = 0,
weekDay: weekDayEnd = index,
year: yearEnd = 0,
},
} = Schedule

return {
start: {
day: dayStart,
hour: hourStart,
minute: minuteStart,
month: monthStart,
second: secondStart,
weekDay: weekDayStart,
year: yearStart,
},
end: {
day: dayEnd,
hour: hourEnd,
minute: minuteEnd,
month: monthEnd,
second: secondEnd,
weekDay: weekDayEnd,
year: yearEnd,
},
}
}
1 change: 1 addition & 0 deletions src/components/ui/SvgIcon/interfaces.ts
Expand Up @@ -2,4 +2,5 @@ export type SvgIconProps = {
src: string
alt: string
title?: string
className?: string
}
7 changes: 6 additions & 1 deletion src/components/ui/SvgIcon/styles.ts
@@ -1,3 +1,8 @@
import styled from 'styled-components'

export const SvgIconStyled = styled.img``
export const SvgIconStyled = styled.img`
width: 1.5rem;
height: 1.5rem;
line-height: 1.5rem;
font-size: 1.5rem;
`
33 changes: 33 additions & 0 deletions src/gql/Query/Schedules/Schedules.graphql
@@ -0,0 +1,33 @@
fragment shedules on Schedules {
Schedule {
...schedule
}
ScheduleMen {
...schedule
}
ScheduleWomen {
...schedule
}
ScheduleFamily {
...schedule
}
}

fragment schedule on Schedule {
start {
...scheduleData
}
end {
...scheduleData
}
}

fragment scheduleData on ScheduleData {
year
month
day
hour
minute
second
weekDay
}
2 changes: 1 addition & 1 deletion src/gql/Query/app.graphql
@@ -1,6 +1,6 @@
query appData {
# Города
cities {
cities(orderBy: { pagetitle: asc }) {
...city
}

Expand Down
2 changes: 2 additions & 0 deletions src/gql/Query/city.graphql
Expand Up @@ -5,6 +5,7 @@ query cities(
$take: Int
$skip: Int
$where: bani684_site_contentWhereInput
$orderBy: [bani684_site_contentOrderByInput!]
) {
cities: cities(
# limit: $resourcesLimit
Expand All @@ -14,6 +15,7 @@ query cities(
take: $take
skip: $skip
where: $where
orderBy: $orderBy
) {
...city
}
Expand Down
4 changes: 4 additions & 0 deletions src/gql/Query/company.graphql
Expand Up @@ -171,6 +171,10 @@ fragment CompanyFields on Company {
description
}

Schedules {
...shedules
}

# schedule @include(if:$companyGetSchedules)
# {
# ...ScheduleDay
Expand Down
12 changes: 10 additions & 2 deletions src/modules/gql/generated/CompanyFields.ts
Expand Up @@ -9,8 +9,13 @@

import * as Types from './types';

import { ShedulesFragment } from './shedules';
import { gql } from '@apollo/client';
export type CompanyFieldsFragment = { __typename?: 'Company', id: number, pagetitle: string, longtitle: string, alias?: Types.Maybe<string>, uri?: Types.Maybe<string>, template: number, published: boolean, searchable: boolean, createdon: globalThis.Date, createdby: number, image?: Types.Maybe<string>, address?: Types.Maybe<string>, workTime?: Types.Maybe<string>, prices?: Types.Maybe<string>, coords?: Types.Maybe<{ __typename?: 'Coordinates', lat: number, lng: number }>, gallery: Array<{ __typename?: 'GalleryImage', image: string, title: string, description: string }> };
import { ShedulesFragmentDoc } from './shedules';
export type CompanyFieldsFragment = { __typename?: 'Company', id: number, pagetitle: string, longtitle: string, alias?: Types.Maybe<string>, uri?: Types.Maybe<string>, template: number, published: boolean, searchable: boolean, createdon: globalThis.Date, createdby: number, image?: Types.Maybe<string>, address?: Types.Maybe<string>, workTime?: Types.Maybe<string>, prices?: Types.Maybe<string>, coords?: Types.Maybe<{ __typename?: 'Coordinates', lat: number, lng: number }>, gallery: Array<{ __typename?: 'GalleryImage', image: string, title: string, description: string }>, Schedules?: Types.Maybe<(
{ __typename?: 'Schedules' }
& ShedulesFragment
)> };

export const CompanyFieldsFragmentDoc = gql`
fragment CompanyFields on Company {
Expand All @@ -37,5 +42,8 @@ export const CompanyFieldsFragmentDoc = gql`
title
description
}
Schedules {
...shedules
}
}
`;
${ShedulesFragmentDoc}`;
2 changes: 1 addition & 1 deletion src/modules/gql/generated/appData.ts
Expand Up @@ -25,7 +25,7 @@ export type AppDataQuery = { __typename?: 'Query', cities: Array<(

export const AppDataDocument = gql`
query appData {
cities {
cities(orderBy: {pagetitle: asc}) {
...city
}
companies_rating: votesByRating {
Expand Down
6 changes: 4 additions & 2 deletions src/modules/gql/generated/cities.ts
Expand Up @@ -18,6 +18,7 @@ export type CitiesQueryVariables = Types.Exact<{
take?: Types.Maybe<Types.Scalars['Int']>;
skip?: Types.Maybe<Types.Scalars['Int']>;
where?: Types.Maybe<Types.Bani684SiteContentWhereInput>;
orderBy?: Types.Maybe<Array<Types.Bani684SiteContentOrderByInput> | Types.Bani684SiteContentOrderByInput>;
}>;


Expand All @@ -28,8 +29,8 @@ export type CitiesQuery = { __typename?: 'Query', cities: Array<(


export const CitiesDocument = gql`
query cities($take: Int, $skip: Int, $where: bani684_site_contentWhereInput) {
cities: cities(take: $take, skip: $skip, where: $where) {
query cities($take: Int, $skip: Int, $where: bani684_site_contentWhereInput, $orderBy: [bani684_site_contentOrderByInput!]) {
cities: cities(take: $take, skip: $skip, where: $where, orderBy: $orderBy) {
...city
}
}
Expand All @@ -50,6 +51,7 @@ export const CitiesDocument = gql`
* take: // value for 'take'
* skip: // value for 'skip'
* where: // value for 'where'
* orderBy: // value for 'orderBy'
* },
* });
*/
Expand Down

0 comments on commit 33596c1

Please sign in to comment.